Slide 1

Slide 1 text

2019/11/10 (Sun) 関数型プログラミングカンファレンス#1 ElixirとHaskellの根底にある同じもの そして、Elixirが辿った道 The same thing that underlies Elixir & Haskell And the road Elixir would have followed 2019/11/07 ver 0.5作成 2019/11/08 ver 0.9作成 2019/11/10 ver 1.0作成

Slide 2

Slide 2 text

1 カラビナテクノロジー株式会社 執行役員 AI学校「AIジョブカレ」福岡代表、技術顧問3社 Elixirコミュニティ「fukuoka.ex」代表、他 森 正和 (piacere) my favotite technology & implements 地元企業向けに、マーケティングSaaS、 データサイエンス、AI・ML、IoT、 量子コンピュータ、宇宙開発などの 先端ITによる「地方創生」活動中!! Twitter/Qiita/Github @piacere_ex or @paicere-ex ==

Slide 3

Slide 3 text

2 Karabiner technology inc: Operating officer AI school "AI Job Colle": Fukuoka Manager Elixir community "fukuoka.ex": Organizaer Masakazu Mori (piacere) my favotite technology & implements Twitter/Qiita/Github @piacere_ex or @paicere-ex For local companies, Marketing SaaS、Data science, ML、IoT、Quantum computing, and Space development... I try Regional revitalization with advanced IT! ==

Slide 4

Slide 4 text

3

Slide 5

Slide 5 text

4 光回線とAmazonが あれば、エンジニアできます If I/you have an optical line and Amazon, I/you can be an engineer

Slide 6

Slide 6 text

5 天神/小倉/沖縄/東京に拠点あり、フルリモート勤務 を実現する、国内トレンドを先行したITスタートアップです 人手不足を感じさせない前年比2倍 (32→75名) 成長 Karabiner technology inc: Operating officer

Slide 7

Slide 7 text

6 機械学習とディープラーニングの 基礎知識およびPython実践 コーディングスキルを半年間に 渡ってみっちり教え、AI開発が 可能な転職先も紹介します AI school "AI Job Colle": Fukuoka Manager

Slide 8

Slide 8 text

7 本当は、みなさまがどんな 関数型を使っているか 聞きたいところですが… I really want to hear what functional language you are using

Slide 9

Slide 9 text

8 Haskell / GHC, Scala, Elm, Rust, Lisp, Scheme, Clojure, F#, OCaml, R, Mathematica, SML, Prolog, GHC, KL1 / KLIC, Lazy K, Shen, Clean, Idris, Miranda, Unlambda, *sh, Excel w...

Slide 10

Slide 10 text

9 懇親会で聞きますね ちなみに、私の関数型の序盤は Scala → Haskell でした I will listen to it at after party The beginning of my FP was Scala -> Haskell, after using various things, and I arrive Elixir

Slide 11

Slide 11 text

10 私が初めてプログラマと なったのは小学校4年生 (37年前) I was in 4th grade (37 years ago) That was when I first became a programmer

Slide 12

Slide 12 text

11 初PC & 母親がくれたPC (First PC, gift PC from mother) ファミコンが世に出たのが7歳位 その1年後、8歳から、勉強そっち のけでBASICでのゲーム開発に 没頭し、その1年後には、Z80の 機械語 (アセンブラじゃ無く、機械 語) を書いていました 今日までの37年間、プログラマと して活動している最大の理由は、 「自ら世界を生み出せる」 という、まるで魔法のようなものに、 魅了され続けているからなのです

Slide 13

Slide 13 text

12 「重力プログラマ」してます (I'm "Gravity Programmer") LIGOの重力波解析コードを解説したり、天体シミュレータ作ったり、 作相対性理論や量子力学のコラムを書いたり、登壇してます

Slide 14

Slide 14 text

13 プログラマを36年続けており、「重力プログラマ」に到達 「重力と宇宙を愛する全ての人に」 #3 "To everyone who loves Gravity and Space" #3

Slide 15

Slide 15 text

14 重力イベント会の様子 (Gravity events looks like this)

Slide 16

Slide 16 text

15 ところでみなさん、Elixirという 言語、聞いたことあります? By the way, have you heard Elixir lang?

Slide 17

Slide 17 text

16 おぉ、それは素晴らしい!(^o^) Oh, very nice! :-)

Slide 18

Slide 18 text

17 では、Elixirを何らかの仕事や 開発で使ったことありますか? Have you ever used Elixir for any work or development?

Slide 19

Slide 19 text

18 そんなあなたに Elixirをご紹介します I introduce Elixir to you

Slide 20

Slide 20 text

19 Elixir、目立ちませんが、実は皆さまを割と支えてます

Slide 21

Slide 21 text

20 Elixir、全世界では、前年比2~3倍で採用グロース中 2016年時点で、1,109社の企業がElixirを採用済 https://www.dailydrip.com/blog/elixir-users-survey-2016-results.html Ruby (Rails)、JS (Node.js)か らの乗り換え需要が大半を占め、 Python、Java、PHPと続く

Slide 22

Slide 22 text

21 特にヨーロッパ方面ではElixirでのFinTechが盛ん メキシコの債務再編企業「RESUELVE」 https://margo.com/ フランスの銀行「Margo Bank」 https://margo.com/ マルゴバンク ベルリンの決済代行「solarisBank」 https://www.solarisbank.com/ リゾルブ

Slide 23

Slide 23 text

22 2017年、GCPが対応 (GCP supported in 2017) GCPが2年前に採用し、Elixirを利用する開発者が、全世界に 拡がり始めました (私達もGCPでの構築を始めました) GCP supported Elixir 2 years ago, developers using Elixir have begun to spread worldwide (We started building with GCP)

Slide 24

Slide 24 text

23 AWSも2018年に対応 (AWS supported in 2018) 続いてAWSも対応し、ますます全世界に拡がっています (話題性は、「COBOL」に全てかっさらわれた感じでしたが…) AWS also supports and is spreading all over the world (The topicality seemed to be "COBOL" ...)

Slide 25

Slide 25 text

24 Elixirコミュ「fukuoka.ex」 についても少しお話します I talk a little about the Elixir community “fukuoka.ex”

Slide 26

Slide 26 text

25 福岡Elixirコミュニティ 2019年6月で3年目突入! ~ Build the future with Elixir and YOU ~ KIEF |> Scalable |> Maintenable |> Productivity |> Speedy |> Friendly |> Simple |> Concurrent |> Fun https://fukuokaex.fun/ Elixir community "fukuoka.ex": Organizaer 福岡Elixirコミュニティ

Slide 27

Slide 27 text

26 福岡市で大人気のElixir コミュニティ「fukuoka.ex」 https://fukuokaex.fun/ 2年強で33回イベント開催、 述べ1,100名もの参加者 が訪れています 福岡以外からも訪れます 今年、海外 (テキサス、コロラド) カンファレンス講演を開始!! Lonestar ElixirConf 2019 ElixirConf US 2019

Slide 28

Slide 28 text

27 ライブデモする「MeetUp」+入門者OKな「もくもく会」 仕事終わり、くつろぎ、ほろ酔いつつ、Elixir/Phoenix による先端プログラミングに触れるイベントを定期開催 ”福岡 Elixir”で検索、メンバー登録で告知届きます (福岡会場参加だけで無く、リモート参加も可能です) ■もくもく会 (毎月、入門者もOK) ■MeetUp (隔月、経験者向け)

Slide 29

Slide 29 text

28 イベント実績 ~立上期からコアメンバー集結まで~ 社内 勉強会 MeetUp #1(24名) 6/8 MeetUp #2(12名) 8/24 Pg入門会 #3(24名) 10/24 MeetUp #4(25名) 12/22 エピソード1「誕生」 MeetUp #5(25名) 2/24 MeetUp #8(33名) 4/20 もくもく会 #6 3/29 もくもく会 #7 4/17 MeetUp #11(60名) 6/22 もくもく会 #9 5/22 もくもく会 #10 7/13 MeetUp #13(100名) 8/24 もくもく会 #12 8/16 fukuoka.ex運用メンバー(この時点で計7名) 2017年6月~ 2018年 エピソード2「仲間」 1イベントで 100名突破 Future Session (全国各地200名) 3/4 200名参加の オンラインライブセッション ~8月

Slide 30

Slide 30 text

29 イベント実績 ~fukuoka.ex、世界と全国に進出!!~ fukuoka.ex運営メンバー (オリジナル7→45名に拡大) 2018年9月~ 2019年 エピソード3「躍動」 5月 エピソード4「熱狂」 fukuoka.ex、遂に海外進出 (テキサス州オースティン) もくもく会 #20 3/15 もくもく会 #22 4/26 もくもく会 #19 1/23 もくもく会 #23 5/28 もくもく会 #25 6/14 全国各地に散らばる Elixirコミュニティ大集合 MeetUp #16 10/26 MeetUp #17 12/14 もくもく会 #14 9/28 もくもく会 #15 11/16 もくもく会 #18 12/21 hibikino.ex 1/23 2拠点 同時開催 kokura.ex 1/25 MeetUp #19 2/18 Elixiroshima 2/24 MeetUp #21 4/17 TechCommit、 Shinjuku.exと 3コミュニティ共催 japan.ex 国内各地域Elixir コミュニティ集合!! 6/2 2/29~3/3 Loanstar ElixirConf 2019 日本人として 初の登壇 6/1 Erlang & Elixir Fest2019 fukuoka.exメンバー 大量参戦 (全22名中、計7名) 福岡に限らず 北海道~沖縄、 都心も含む 全国各地の Elixirプレイヤー fukuoka.ex 運営に参画

Slide 31

Slide 31 text

30 Elixirの論文発表 (Elixir paper is also published)

Slide 32

Slide 32 text

31 今年、海外 (テキサス、コロラド) カンファレンス講演を開始!! Lonestar ElixirConf 2019 ElixirConf US 2019 先端研究プロダクト開発 今年、全世界デビュー達成!! Pelemay (Multicore driver) Cockatrice (FPGA driver)

Slide 33

Slide 33 text

32 小倉城 天守閣と北九州 芸術劇場を繋ぐ 100名規模カンファレンスを9/7開催しました! https://fukuokaex.fun/

Slide 34

Slide 34 text

33 国内Elixirコミュニティ: 2年半前…

Slide 35

Slide 35 text

34 国内Elixirコミュニティ: 現在18件!!

Slide 36

Slide 36 text

35 リモート参加可! (Many events can participate remotely) • fukuoka.ex(福岡) • kokura.ex(福岡) • hibikino.ex(福岡) • Elixir |> College(福岡) • エリジョ(福岡) • 九州国際Elixir連盟(九州) • Elixiroshima(広島) • Kochi.ex(高知) • Kyoto.ex(京都) • 清流elixir(岐阜) • tokyo.ex(東京) • Shinjuku.ex(東京) • akiba.ex(東京) • Sapporo.beam(北海道) • Erlang & Elixir Fest【JEA】 • japan.ex • ElixirConf JP • Nerves JP ※ はリモート参加OKイベント

Slide 37

Slide 37 text

36 それでは本編です 注※: Haskellの情報は間違っている可能性あるかも なので、後でコッソリ教えてくださいm(__)m Today's main *Haskell information may be wrong, please tell me later

Slide 38

Slide 38 text

37 HaskellとElixirが生まれた背景 (Background to the birth of Haskell & Elixir)

Slide 39

Slide 39 text

38 各々の生まれた背景 (Background to the birth) ➢ Birth: 1990 (29 years ago) ➢ Before OOP • Leaders: C/Pascal • Ada特需w (米国の納品で) ➢ Birth: 2012 (7 years ago) ➢ After OOP • Leaders: Java/JS/PHP • AI・ML需要でPython※ 台頭 ※Python、実は1991年生まれ (28 years ago) 最近、出てきた雰囲気は、AI・MLによるもので、言語 自体は、若い世代では無く、すでに薹が立っているw

Slide 40

Slide 40 text

39 各々の生まれた背景 (Background to the birth) ➢ GHC (Glasgow Haskell Compiler) is mainstream • Previously there were other implementations ➢ Maintener: Simon Peyton Jones (SPJ), Simon Marlow • 2人を雇うMicrosoftが、主要 スポンサー ➢ Haskell is mostly written in Haskell • Runtime system written in C ➢ Run on ErlangVM (BEAM) • Erlang: 1986 (33 years) • Age close to Haskell ➢ Maintener: José Valim ➢ Elixir is mostly written in Elixir • booter written in Erlang

Slide 41

Slide 41 text

40 オレオレElixir作る会 (Bootstraping Elixir Meetup) Elixir本体は、大半がElixirで書かれていることを利用して、みんな で「オレオレElixir」を作るという、もくもく会を先月、開催しましたが、 Elixir本体を改造して、ビルドする経験の共有は、ステキでした Using the fact that Elixir is written in Elixir, we held coding meetup to make "Myself Elixir" together last month, sharing experience of remodeling & building Elixir was very wonderful +

Slide 42

Slide 42 text

41 余談: フェラーリ≒Erlang? (Is Erlang like Ferrari?) 「Erlangはポンコツの板金に包まれたフェラーリのようなもの」と揶揄 される程、難解な構文で、これを本物のフェラーリにするのがElixir Erlang is the esoteric syntax that is deceived as "Ferrari wrapped in the sheet metal of an old beater", and Elixir solves it to be a real Ferrari https://thoughtbot.com/blog/testing-a-phoenix-elixir-json-api

Slide 43

Slide 43 text

42 HaskellとElixirの特徴 (Haskell & Elixir features)

Slide 44

Slide 44 text

43 HaskellとElixirの特徴 (Haskell & Elixir features) ➢ List based pure FP with lazy • Pattern match & Guard • Higher-order func & DSL ➢ Powerful type programming ➢ Features • Powerful type system • Generic & type safety • Polymorphism • Overloading • Prelude: builtin funcs • Operators • List processors • Fusion mechanism of pure and side effects ➢ List based FP with lazy • Pattern match & Guard • Higher-order func & DSL ➢ Concurrent programming ➢ from Erlang features • Concurrent & distributed • Process oriented • Fault tolerance/Non-stop • Low latency to Realtime ➢ like list processing ➢ like build systems ➢ like modern syntax ➢ like Web Framework ➢ like powerful macro

Slide 45

Slide 45 text

44 "Lisp was amazing from 60 years ago!!" Birth: 1958 (61 years ago!!) Lisp is second oldest high-level programming language after FORTRAN List processing based programming style Source code can be handled as data, Allows LISP to be written in LISP

Slide 46

Slide 46 text

45 関数型は新しく無い (Functional programming (FP) is not new) 「Pythonは若い言語」と間違えるのと同じく、関数型が「新しい」と 勘違いする人も多いですが、関数型は新しくありません…むしろ、 前述の通り、最古の部類です Just as there are people who misunderstand that "Python is new language"', people misunderstand "FP is new'', but it's not a new concept, as mentioned before 昔は、多くの人が追いつけてなかったし、必要性も無かったですが、 マルチコアCPU時代+クラウド分散を迎え、需要が高まりました In the past, many people could not catch up and the necessity was not high, but need has increased with the arrival of the multi-core CPU era + cloud distributed

Slide 47

Slide 47 text

46 マルチコアCPUをドライブする (Driving multi core CPU) 2003年以前は、CPU周波数が上昇し続け、関数型無でも性能 は向上し続けましたが、2003年以降、マルチコアCPU主流となり、 性能向上のために関数型が求められる状況となりました Before 2003, CPU frequency continued to rise and the performance was raised even without the FP, but since 2003, multi core CPU has become mainstream, and the FP has been required to improve the performance

Slide 48

Slide 48 text

47 誤解されやすいElixir型付け (Elixir typing is easy to mistake) Elixirは、動的型付けの言語であることから、JavaScriptやRuby、Python と同列視されることがありますが、Elixirは「強い型付け」の動的型付け言語で あり、コンパイルタイムに型チェックが走るため、「弱い型付け」である上記言語 が、ランタイムまで型チェックされないのとは、異なる型安全性を保持しています Elixir is dynamically typed language, it's often confused with languages with weak type checking, such as JavaScript, Ruby, and Python, However, Elixir is "strongly typed" dynamic typing language that performs type checking at compiling, so it maintains type safety that is quite different from the above-mentioned languages that are "weakly typed" that are not type checked until runtime とはいえ、ランタイムにならないと判明しない型チェック漏れも存在しているため、 そこを補完するための静的チェッカーとして「Dialyzer」が提供されてます However, there is a type check omission that is not known unless it becomes runtime, so "Dialyzer" is provided as a static checker to complement it

Slide 49

Slide 49 text

48 ElixirとHaskellのインストール (Installing Elixir & Haskell)

Slide 50

Slide 50 text

49 ElixirとHaskellインストール (Installing Elixir & Haskell) Dockerを使えば、OS周りのトラブル※無くインストールできて簡単 ※Homebrewでパスが通らなかったり、yumで落としてきたら古かったり… With Docker, it's easy to install without trouble* around OS *Path is not set when installing with Homebrew, Version is old when installing with yum... $ docker pull haskell $ docker pull elixir

Slide 51

Slide 51 text

50 ElixirとHaskellインストール (Installing Elixir & Haskell) Dockerでは無く、各OS毎のバイナリインストーラで入れたい場合、 公式サイトで入手できます ※Windowsはバイナリでトラブらないw If you want to install with bin installer for each OS instead of Docker, you can get it on official web *Windows doesn't have trouble with bin https://elixir-lang.org/install.html https://www.haskell.org/downloads/

Slide 52

Slide 52 text

51 ElixirとHaskellインストール (Installing Elixir & Haskell) どちらもREPLがあるので、簡単に素早くコードを試せます Both have REPL, so you can easily and quickly try out codes $ ghci Prelude> 2 + 3 5 Prelude> sum [ 1, 2, 3 ] 6 $ iex iex> 2 + 3 5 iex> Enum.sum [ 1, 2, 3 ] 6

Slide 53

Slide 53 text

52 ElixirとHaskellインストール (Installing Elixir & Haskell) ソースコードをコンパイルして実行することも、もちろんできます You can of course compile and run source codes $ ghc sample.hs [1 of 1] Compiling Main ( sample.hs, sample.o ) Linking sample.exe ... $ ./sample 6 $ mix escript.build ==> logger_file_backend Compiling 1 file (.ex) ... $ ./sample 6

Slide 54

Slide 54 text

53 ElixirとHaskellインストール (Installing Elixir & Haskell) ソースコードをロードしつつ、REPL起動することも可能です You can also start REPL while loading source code for execution $ ghci sample.hs Prelude> [1 of 1] Compiling Main ( sample.hs, interpreted ) Ok, one module loaded. *Main> my_sum [ 1, 2, 3 ] 6 $ iex -S mix ==> logger_file_backend Compiling 1 file (.ex) ... iex> my_sum [ 1, 2, 3 ] 6

Slide 55

Slide 55 text

54 ElixirとHaskellインストール (Installing Elixir & Haskell) REPLの中で、変更したソースコードをリビルドすることも可能です It's also possible to rebuild modified source code in REPL *Main> :reload [1 of 1] Compiling Main ( sample.hs, interpreted ) Ok, one module loaded. *Main> my_sum [ 1, 2, 3 ] 36 iex> recompile Compiling 1 file (.ex) :ok iex> my_sum [ 1, 2, 3 ] 36

Slide 56

Slide 56 text

55 Elixir/Haskellで関数を書く (Writing Elixir / Haskell functions)

Slide 57

Slide 57 text

56 名前付き/無名関数 (Named / anonymous functions) 「名前付き関数」と「無名関数」が定義できます Functions can be defined as "named function" and "anonymous function" Prelude> f = ¥x -> x + x Prelude> f 2 4 iex> defmodule Sample do ...> def named_func( x ), do: x + x ...> end iex> Sample.named_func 2 4 iex> f = fn x -> x + x end iex> f.( 2 ) 4 Prelude> named_func x = x + x Prelude> named_func 2 4

Slide 58

Slide 58 text

57 関数パターンマッチ (Function pattern matching) 同名関数を定義すると、引数の内容で挙動を変えられます If a function with the same name is defined, behavior can be changed by the content of the arguments Prelude> :{ Prelude| my_name_is "hoge" = "foo" Prelude| my_name_is me = "I'm " + me Prelude| :} Prelude> my_name_is "hoge" "foo" iex> defmodule Sample do ...> def my_name_is( "hoge" ), do: "foo" ...> def my_name_is( me ), do: "I'm #{ me }" ...> end iex> Sample.my_name_is( "ghost" ) "I'm ghost" iex> Sample.my_name_is( "hoge" ) "foo"

Slide 59

Slide 59 text

58 関数パターンマッチ (Function pattern matching) 関数パターンマッチは、たとえば、Webフォーム処理で、入力内容 により挙動を変える場合などに、便利に使えます Function pattern matching can be used conveniently, for example, when changing the behavior according to input contents in Web form processing def type( nil ), do: "" def type( "" ), do: "" def type( 1 ), do: "予約後" def type( 2 ), do: "返信済み" def type( 3 ), do: "受付済み" Elixirは、SPA+APIか「LiveView」で リアルタイムUI処理を簡単に実現可能 Elixir can easily realize real-time UI with SPA + API or "LiveView"

Slide 60

Slide 60 text

59 再帰関数 (Recursive function) 関数パターンマッチを応用して、再帰的に処理する関数を書けます (が、私の周りにいるアルケミスト/Haskellerは、再帰を封印しても問題無いため、データ処理最適化 と可読性の都合上、再帰を利用禁止にしている人が多いです) Apply function pattern match to define recursive function (However, the Alchemist / Haskeller around me has no problem even if recursion is sealed, so many people forbid recursion for data optimization and readability)

Slide 61

Slide 61 text

60 余談: アルケミスト (Digression: Alchemist) Elixir使いのことを、「アルケミスト」と呼びますが、不老不死の霊薬 である「エリクサー」を扱うことから、このネーミングになったようです Elixir developer is called “Alchemist”, it seems that this naming came from dealing with “Elixir”, immortal medicine 同名のこれら本は、とても 良い本でオススメです These books with the same name are very good books and we recommend them

Slide 62

Slide 62 text

61 リスト処理と高階関数 (List processing and higher order function)

Slide 63

Slide 63 text

62 リスト要素に関数適用 (Applying function to list elements) リスト処理であるmapやfilterを使うと、リストの各要素に、関数を 適用していきます (Elixirはリストを第一引数とし、Haskellは第二引数とします…後で出ます) When using map and filter that is list processing, the function is applied to each element of the list (Elixir takes list as the first argument, Haskell takes list as the second argument) Prelude> map ( * 2 ) [ 1, 2, 3 ] [2,4,6] Prelude> filter ( > 5 ) [ 1..10 ] [6,7,8,9,10] iex> Enum.map [ 1, 2, 3 ], & &1 * 2 [2, 4, 6] iex> Enum.filter 1..10, & &1 > 5 [6, 7, 8, 9, 10]

Slide 64

Slide 64 text

63 iex> Enum.map [ 1, 2, 3 ], & &1 * 2 [2, 4, 6] iex> Enum.filter 1..10, & &1 > 5 [6, 7, 8, 9, 10] 高階関数としての定義 (Definition as higher order function) mapやfilterを始めとするリスト処理は、引数として渡された関数 (下記赤囲み) を処理していく「高階関数」として定義されています List processings are defined as "higher order functions", they apply the function passed as an argument (red box below) Prelude> map ( * 2 ) [ 1, 2, 3 ] [2,4,6] Prelude> filter ( > 5 ) [ 1..10 ] [6,7,8,9,10]

Slide 65

Slide 65 text

64 Elixirのパイプ演算子 (Elixir's pipe operator) Elixirでは、"|>"を使うことで、処理結果を次の関数の第一引数 に渡すことができるので、Unixの「シェル」のように、流れるデータを 主体とするプログラミングができます ※リストが第一引数なのはこのため Elixir uses "|>" to pass processing result to first argument of next function, so you can program based on data flow like a Unix "shell" **This is why Elixir makes list the first argument** これにより、データ処理が直感的かつ楽しく書けます As a result, data processing coding are intuitive and fun [ 323, 999, 54 ] |> Enum.sort |> Enum.map & &1 * 2 |> Enum.map & &1 + 3 iex> [ 1, 2, 3 ] |> Enum.map & &1 * 2 [2, 4, 6]

Slide 66

Slide 66 text

65 リスト処理、他は? (What about other list processing?) Elixir/Haskell共にコラム化しているので、ご覧ください Below column was both Elixir / Haskell other list processing description https://qiita.com/piacerex/items/e9215d12018288c7595b

Slide 67

Slide 67 text

66 Elixirのリスト処理 (Elixir list processing functions) Elixir公式リファレンスのEnumモジュールに例付で記載されてます In described with example in the Enum module of Elixir official reference https://hexdocs.pm/elixir/Enum.html

Slide 68

Slide 68 text

67 リスト処理を応用すると… (Applying list processing...) 以下のような、昨今のWebアプリやスマホアプリで頻出する処理を、 とてもカンタンに構築することができます You can easily build features that frequently for Web apps and Smartphone apps such following ➢ DBデータ加工/変換 (DB data transform processing) ➢ API呼出時のJSONパース後データ処理 (Post-JSON parsing data processing when calling APIs) ➢ BFF (Backends For Frontends): 複数APIの合成 (Composing multiple APIs) ➢ 画像フィルタ処理 (Image filtering) ➢ AI・ML/データサイエンス (AI / ML and Data science) etc...

Slide 69

Slide 69 text

68 入門者向けElixir (We’re teaching Elixir for beginner) Elixirでは、データの並べ替えに、Enum.sort()を使います For data sorting, you can use Enum.sort() iex> Enum.sort [ 323, 999, 54 ] [54, 323, 999] iex> Enum.sort [ 323, 999, 54 ] [54, 323, 999]

Slide 70

Slide 70 text

69 Qiitaでコラム化しています (It's columnized on Qiita) 「Elixir Excel」でググると、入門者向けコラム群が見つかります Search for "Elixir Excel", you can find series columns for beginners

Slide 71

Slide 71 text

70 他のだいたい同じもの (Other roughly same features) 今回は、時間の都合で説明を省略しますが、ElixirとHaskellの 以下は、シンタックスは異なるものの、ほぼ同じように記述できます The following for Elixir and Haskell can be written almost same feeling (syntax is slightly different), but I’ll omit today because time is short ➢ ガード (Guard) ➢ リスト内包表記 (List comprehension) ➢ 遅延評価※、無限リスト (Lazy evaluation and infinite list) ※HaskellのデフォルトはLazyだが、ElixirはStreamモジュール以外がEager、という違いある 詳しくは、これらの本を 参照してください Please refer to these books for more information

Slide 72

Slide 72 text

71 ここまでが両言語の類似性で、 根底にある同じものを 感じていただけたでしょうか? So far, there are similarities between the both languages, Can you feel same underlying?

Slide 73

Slide 73 text

72 HaskellにあってElixirに無いもの (What exists in Haskell but not in Elixir)

Slide 74

Slide 74 text

73 Haskllだけが持っているもの (What only Haskell has) ① コンパイルタイムの静的型チェックによる「型安全」の保証 (Guaranteeing "type safety" with static type checking at compiling) ② 代数的データ型 (Algebraic data types) / 型クラス / Functor / Applicative / Monad • 「struct」で直積型は再現できるが、直和型は無い (Product can be reproduced with "struct", but there is no union) • 「algae」「type_class」「witchcraft」で似た感じにはできますが、 型付けが異なる以上、副作用の分離は保証できない (You can approximated by "algae / type_class / witchcraft", but the separation of side effects cannot be guaranteed with different typing) ③ Monoid / Foldable / Traversable • defprotocol / defimplを用いて、汎用関数を作成するところまで は再現可能だが、上記同様の制約がある (You can be reproduced up to the creation of a general-purpose function using defprotocol / defimpl, but there are same restrictions as above)

Slide 75

Slide 75 text

74 ElixirにあってHaskellに無いもの (What exists in Elixir but not in Haskell)

Slide 76

Slide 76 text

75 Elixirだけが持っているもの (What only Elixir has) ① 親しみやすい関数型 (Friendly functional programming) ② OTP: 並行プログラミングFW (Concurrent programming FW) • GenServer: 再帰無しのサーバ待受プロセス標準を提供 (Provides a server standby process standard without recursion) • Supervisor: プロセス監視メカニズムによるプロセスダウンの 検出とプロセス再起動/フックを提供 (Provides process down detection and process restart / hook with process monitoring mechanism) ③ 「Enum」を「Flow」と書き換えたらマルチコアCPU化 (If you rewrite "Enum" as "Flow", you can drive multi-core CPU) ④ マクロによるメタプログラミング (Meta-programming with macro) • 柔軟な言語拡張/DSL定義を提供 (Provides flexible language extensions and DSL definitions)

Slide 77

Slide 77 text

類似点も多い関数型同士なのに これら違いは何故出るのでしょう? Why are these differences even though the same FP and there are many similarities?

Slide 78

Slide 78 text

77 Haskellは、強力な型安全を背景とし、Maybe やモナド等を用いて、以下を実現します With strong type safety in mind, Haskell uses Maybe and monads, etc. to: ➢ 統一的なエラー処理 (unified error handling) ➢ 純粋関数により得られる参照透過性 (referential transparency gained by pure functions) ➢ 型安全な汎用関数プログラミング (Type-safe general functional programming)

Slide 79

Slide 79 text

78 Elixirは、以下の着想に基づいて、設計されています Elixir has designed based on the following thoughts: ➢ プログラムは人が書くものだからバグは避けられない (Bugs are inevitable because programs are written by humans) ➢ システムは、支配下以外にも依存する (System also depends on side effects other than under control) ➢ よって、全てのエラーを把握してコードを書くことは、 不可能である (Therefore, it is impossible to write code that understands all errors) ➢ なので、「エラーは必ず発生する」を前提としよう (So, Let's assume that an error always occurs)

Slide 80

Slide 80 text

つまり、戦略の違いと、それに伴う設計 哲学の違いから、差が生まれている In other words, it's born from the difference in strategy and the difference in design philosophy that accompanies it

Slide 81

Slide 81 text

80 私達がElixirをオススメする理由 (Why we recommend Elixir?)

Slide 82

Slide 82 text

81 ①利益を簡単に得られる (You can get benefits easily) 「関数型言語」「並行言語」の良さと、モダンWeb開発の両面で、 先端技術の利益を、気軽に得られることが、Elixirの強み ➢ アプリ開発で最重要なのはデータ処理とすぐに実感できる ➢ 「イミュータブル」と「シェアードナッシング」を最も学びやすい ➢ 並行/分散、耐障害性が日常になる ➢ 「Phoenix」 モダンWeb開発の堅い土台からスタートできる You can get easily benefits for edge technology from Elixir, including excellent aspects of "functional languages" and "parallel languages", and modern Web devs, for examples: ➢ You can immediately realize that the most important thing in app devs is data processing ➢ Easiest way to learn "immutable"&"shared nothing" ➢ Concurrency / distributed & fault tolerance become everyday ➢ "Phoenix": You can start from solid basis for modern web devs

Slide 83

Slide 83 text

82 ②副作用はプロセスに (Side effects are isolated to processes) Elixirでは、状態やIO、DB等の副作用は「生きているプロセス」 に持たせる割り切りをすることで、複雑さを無くしています Elixir has decided to isolate side effects such as state, IO, DB, etc. into "running process", to remove complexity その前提が軽量プロセスですが、Elixirプロセスは、数十万から 数千万、1台のPC上で起動しても問題無く、更にCPU負荷は、 プロセス数に比例し、二次曲線的では無く、シーケンシャルです (驚くべき事実です!!) The premise is a lightweight process, Elixir's process can be concurrent running from 100,000 - 50,000,000 on single PC, and processing load rises sequentially, not as a quadratic curve, depending on the number of processes (It's amazing fact!!)

Slide 84

Slide 84 text

83 ②副作用はプロセスに (Side effects are isolated to processes) 実際に、任意の処理を行うプロセスを、3,000万件まで増やし 続ける実験を行ったところ、CPU負荷はプロセス数に比例して、 ほぼシーケンシャルに上昇していることを確認しています We conducted an experiment to increase the number of Elixir processes that perform arbitrary calculation processing to 30 million, and confirmed that the CPU load was increasing almost sequentially in proportion to the number of processes

Slide 85

Slide 85 text

84 ②副作用はプロセスに (Side effects are isolated to processes) 副作用をプロセスに持たせることで、別クラスタに副作用を移動 可能とする…つまり「分散」も容易に叶えます By isolate the process side effects, you can move them to another cluster, as a result, “distribution” can be easily これは、QNXやL4カーネルファミリー、Google Fuchsiaの Zirconといった、「マイクロカーネルOS」の世界観と全く同じです (ちなみに、LYMEというErlangベースのOSスタックも昔あったようです) This worldview is exactly the same as the “microkernel OS” such as QNX, L4 kernel family, and Google Fuchsia/Zircon (By the way, LYME was Erlang-based OS stack)

Slide 86

Slide 86 text

85 ②副作用はプロセスに (Side effects are isolated to processes) こうした考え方の延長上に、インメモリDB「ETS」がElixirに標準 バンドルされており、SQLiteのように気軽に利用できます (SQLiteや他DB同様、トランザクションもきっちりサポートされて います…MyISAM的なものでは無いw) In extension of this idea, the in-memory DB “ETS” is bundled as Elixir standard and can be used easily like SQLite (As with SQLite and other DB, transactions are also supported... It’s not like MyISAM) 更に、「Mnesia」に至っては、複数クラスタ間で同期が可能な、 分散インメモリDBで、こちらも標準バンドルです Furthermore, "Mnesia" is a distributed in-memory database that synchronizes between multiple clusters, and this is also a Elixir standard bundle

Slide 87

Slide 87 text

86 ②副作用はプロセスに (Side effects are isolated to processes) プロセスの代わりに、Stateモナド (型の安全性は無いけど) にて 状態保持も可能で、局所的な性能改善として効果があります You can also possible to hold the state with State monad (but there is no type safety) instead of the process, which is somewhat effective as a local performance improvement しかし、その数百倍~数千倍は性能改善できる、Discord製の ライブラリ「FastGlobal」を使う方が、一般的です However, it is more common to use the FastGlobal library provided by Discord, which can improve the performance by several hundred to several thousand times https://github.com/discordapp/fastglobal

Slide 88

Slide 88 text

87 ③Webがパワフル (Elixir's Web is very powerful) Elixirは、「Phoenix」のWeb+DB/API開発が、Rails並に パワフルで、WebSocketやフロントレンダリングといった、モダンな Web開発のための機能が一通り揃っています Elixir & “Phoenix” Web + DB / API devs is as powerful as Rails, and it also has all the functions for modern Web devs such as WebSocket and front rendering, and more <% datas = [ %{ "name" => "enぺだーし", "age" => 49 }, %{ "name" => "ざっきー", "age" => 45 }, %{ "name" => "つちろー", "age" => 34 }, %{ "name" => "piacere", "age" => 43 }, ] |> Enum.sort &( &1[ "age" ] < &2[ "age" ] ) %> <%= for data <- datas do %> <%= data[ "name" ] %> <%= data[ "age" ] %> <% end %>

Slide 89

Slide 89 text

88 ③Webがパワフル (Elixir's Web is very powerful) 以下のような、昨今のWebアプリやスマホアプリで頻出する処理を、 とてもカンタンに構築することができます You can easily build features that frequently for Web apps and Smartphone apps such following ➢ DBデータ加工/変換 (DB data transform processing) ➢ API呼出時のJSONパース後データ処理 (Post-JSON parsing data processing when calling APIs) ➢ BFF (Backends For Frontends): 複数APIの合成 (Composing multiple APIs) ➢ 画像フィルタ処理 (Image filtering) ➢ AI・ML/データサイエンス (AI / ML and Data science) etc...

Slide 90

Slide 90 text

89 ③Webがパワフル (Elixir's Web is very powerful) 「Elixir Excel 2」で、Phoniexのインストールから始められます Search for "Elixir Excel 2", Let's try install Phoenix & learn

Slide 91

Slide 91 text

90 Gigalixirでリリース (Release with Gigalixir) 本番環境の構築は、面倒なものですが、GigalixirというElixirの PaaSを使うと、git pushするだけで本番リリースができます Building a production is cumbersome, but if you use Elixir's PaaS called Gigalixir, you can release it with only git push

Slide 92

Slide 92 text

91 Gigalixirコラムもあります (See Gigalixir column) 「Gigalixir」でググれば、Gigalixirでの本番リリース手順あります Search for "Gigalixir", Let's try production release by Gigalixir

Slide 93

Slide 93 text

92 ④データサイエンス向き (Elixir is for "data science") Elixirは、データ群の変換/クレンジング/融合/解析が組み やすいため、「データサイエンス」…つまり、データ前処理や分析系、 AI・MLといったシステムの構築に、非常に向いています Elixir is very suitable for the construction of systems such as data preprocessing, analysis systems, AI / ML, etc., because the transforming / cleansing / fusion / analysis of datas is easy 更に、Webもパワフルなため、分析データのビジュアライゼーション やダッシュボードの構築、データ検索UIの構築にも強いです In addition, because the Web is powerful, it is also strong in the visualization of analytical data, the construction of dashboards, and the construction of data search UI

Slide 94

Slide 94 text

93 ④データサイエンス向き (Elixir is for "data science") 下記のような、DB接続や外部システム接続も伴う、データ分析 アプリケーションが、数時間程度で作れます You can create data analysis app including DB connections and external system connections in few hours

Slide 95

Slide 95 text

94 Esuna (エスナ) : Data science platform Web操作だけで、CSV/Excel/DB/AWS/GCP/汎用 APIといったデータを取り込み、変換/集約/クレンジング可能 Esuna can import, convert, aggregate, and cleanse data such as CSV / Excel / DB / AWS / GCP / general-purpose APIs with just a web ops

Slide 96

Slide 96 text

95 Esuna (エスナ) : Data science platform Python製ディープラーニングライブラリである「Keras」のコードを 自動生成する機能もあります There is also a function to automatically generate code for ”Keras"', a Python deep learning library

Slide 97

Slide 97 text

96 ④データサイエンス向き (Elixir is for "data science") データハンドリングのしやすさから、私達はElixirを「関数型言語」と は呼ばず、「データ処理言語」と呼んでいます Because of the ease of data handling, we don't call Elixir a "functional language" but a "data processing language"

Slide 98

Slide 98 text

97 ④データサイエンス向き (Elixir is for "data science") 現在、LabVIEWやVerilog等に限定される「データフロー言語」を Web開発やAI・ML開発の領域で使用可能とするのが、Elixir の強みです Elixir's strength is that it is now possible to use "data flow languages" that are limited to LabVIEW, Verilog, etc. in the areas of web devs and AI / ML devs 本来は、データフロー言語が目標としていた、 「並行プログラミングを簡単にする」は、Elixirで実現できます Originally, the goal of data flow language, “Easy concurrent programming” can be realized with Elixir

Slide 99

Slide 99 text

98 ④データサイエンス向き (Elixir is for "data science") Flowのカバー範囲は、マルチコアCPUに限定されるので、 SIMD命令やGPUをカバーする「Pelemay」を、fukuoka.ex の北九大 山崎先生が開発し、今年の3月と9月、ElixirConf で発表してきました Since the coverage of Flow is limited to multi-core CPU, zacky of fukuoka.ex was developed “Pelemay” of OSS that covers SIMD instructions and GPU and announced at ElixirConf in March and September this year また、FPGAに対しても、「Cockatrise」というElixir実装を kyoto.exの京大 高瀬先生が9月に海外発表してきました For FPGA, Elixir implementation called "Cockatrise" has been developed by takase of kyoto.ex / fukuoka.ex, which was announced overseas in September this year

Slide 100

Slide 100 text

99 Pelemay (ペレメイ) : SIMD & GPU driver https://www.youtube.com/watch?v=uCkPyfFhPxI

Slide 101

Slide 101 text

100 Cockatrice (コカトリス) : FPGA driver https://www.youtube.com/watch?v=BJbXpwS-g1A

Slide 102

Slide 102 text

101 ⑤IoTにも強い (Elixir is also strong against IoT)

Slide 103

Slide 103 text

102 ⑤IoTにも強い (Elixir is also strong against IoT)

Slide 104

Slide 104 text

103 ⑤IoTにも強い (Elixir is also strong against IoT)

Slide 105

Slide 105 text

104 ⑥充実したコミュニティ (Elixir communities are fullness) 「勢い」と「スピード」、「熱量」、「厨二病感」が半端無い18箇所 “Momentum”, “Speed”, “Passion”, and “Sense of Sophomoric” far exceed common sense, in 18 communities • fukuoka.ex(福岡) • kokura.ex(福岡) • hibikino.ex(福岡) • Elixir |> College(福岡) • エリジョ(福岡) • 九州国際Elixir連盟(九州) • Elixiroshima(広島) • Kochi.ex(高知) • Kyoto.ex(京都) • 清流elixir(岐阜) • tokyo.ex(東京) • Shinjuku.ex(東京) • akiba.ex(東京) • Sapporo.beam(北海道) • Erlang & Elixir Fest【JEA】 • japan.ex • ElixirConf JP • Nerves JP

Slide 106

Slide 106 text

105 ⑥充実したコミュニティ (Elixir communities are fullness) 最近、Elixirコミュニティ同士が同日でバッティングして、どちらかに しか参加できないケースが頻発しました Recently, there were frequent cases where Elixir events batting on the same day and can only participate in one こういうケースでは、多くのコミュニティが、リモート参加OKな利点 を活かし、2拠点ジョイント開催で繋ぐ交流機会も増えています In such cases, many communities are taking advantage of the benefits of remote participation and more opportunities to interact with each other through joint

Slide 107

Slide 107 text

106 ⑥充実したコミュニティ (Elixir communities are fullness) + + 9/29: tokyo.ex + fukuoka.exでオレオレElixirを作る会w 11/15: fukuoka.ex+清流elixir (東海) でマクロのハック会

Slide 108

Slide 108 text

107 ⑥充実したコミュニティ (Elixir communities are fullness) 最近は、Elixir入門者向けのコミュニティも、着々と増えています Recently, the community for Elixir beginners has been steadily increasing

Slide 109

Slide 109 text

108 ⑥充実したコミュニティ (Elixir communities are fullness)

Slide 110

Slide 110 text

No content

Slide 111

Slide 111 text

110 ElixirConf JP初開催 (ElixirConf JP held for first time) 今年9月、ElixirConfを日本で初開催し、 地方にも関わらず、100名超えの大盛況 In September of this year, ElixirConf was held in Japan, and it was a great success with more than 100 people, despite being held locally

Slide 112

Slide 112 text

111 目玉①: 本格IoT開発が気軽にできるコアライブラリを 提供する海外Elixirスーパーエンジニアが基調講演

Slide 113

Slide 113 text

112 Nerves: ElixirでIoT開発+ライブファームウェア更新 Nerves: IoT devs and live firmware update at Elixir

Slide 114

Slide 114 text

113 目玉②: 国内熟練Elixirプレーヤー8名と、Elixir導入企業2名、 Lightning Talk 7名によるElixir最新事例+先端研究

Slide 115

Slide 115 text

114 近い未来をElixirで実現する (Realizing near future with Elixir) 水力発電でIoT、地方の「仮想発電所」構想 登山データの活用/共有/高速データ処理 家具販売におけるXR活用 土木データ (地形、計画、用地境界) の即時処理

Slide 116

Slide 116 text

115 実はHW変更無で100倍速くできる (x100 faster without change HW) ElixirでマルチコアCPU並列処理 を容易にプログラミング可能とし、 18~100倍、高速に Elixir上で、通常のGPU利用よりも4~8倍、高速に

Slide 117

Slide 117 text

116 12年先のIoT/AI・ML/Webを3年後にElixirで実現 We will realize 12 years ahead IoT/AI&ML/Web on 3 years

Slide 118

Slide 118 text

117 目玉③: ”fukuoka.ex祭り” 締括り祭事 「南原神楽」 舞台講演

Slide 119

Slide 119 text

118 目玉④: 城の麓で、ライトアップされた小倉城を見ながら懇親会

Slide 120

Slide 120 text

119 Presented by & Kyushu International Elixir Federation

Slide 121

Slide 121 text

福岡でこんな展開しています We're going to develop in Fukuoka

Slide 122

Slide 122 text

121 【福岡でのElixir事例①】 福岡市で2年前に始めた Elixirプロダクション採用

Slide 123

Slide 123 text

122 福岡で進むElixirプロダクション導入 山登りアプリで有名な自社サービスの「検索サジェストサーバ」を Elixir+Phoenix+ElasticSearchで動作させているが、1年 以上、ダウンしたことが無く、放ったらかしでの運用を実現 近日、画像メディアサーバをリリースするが、こちらは画像アップ ロードによる負荷で他APIが詰まるのを回避することが目的 AWS EC2上のDockerに、Elixirを入れて 運用しており、利用DBはMongoDB 複数サービスの負荷をElixirで低減した事例 fukuoka.exポータルでインタビュー公開中 https://fukuokaex.fun/fukuokaex

Slide 124

Slide 124 text

123 福岡で進むElixirプロダクション導入 LINE Clovaのスキル開発が、Elixirで可能となっています https://github.com/line/clova-cek-sdk-elixir LINE Developer Meetup #38 で本日セッション予定のアダムさんが Elixir構文について登壇&デモ

Slide 125

Slide 125 text

124 福岡で進むElixirプロダクション導入 個性的かつ機能的な家具で有名な、ベガコーポレーションR&D チームは、Elixirの性能検証を行い、「検証間違い?」と思える 程の高性能を5末に体感し、検討を進めた結果、プロダクション 採用が決まり、現在、新プロダクト開発中です fukuoka.exポータルでインタビュー公開中 https://fukuokaex.fun/fukuokaex

Slide 126

Slide 126 text

125 福岡で進むElixirプロダクション導入 EC/情報サービス/流通系システム/製造業向けツールなど、 ごくありふれたSI案件を、Elixir+Phoenix (フロントはVue.js、 Angular、React、Flutterなど様々) で実現しています GCP GCE/GKE上に、Elixirを直接 入れて運用し、利用DBはCloudSQL 今後、BigQuery/Spannerによる ビッグデータ処理も組み合わせていく fukuoka.exポータルでインタビュー公開中 https://fukuokaex.fun/fukuokaex

Slide 127

Slide 127 text

126 【福岡でのElixir事例②】 北九州における半年間の Elixir導入開始事例

Slide 128

Slide 128 text

127 ①全国/全世界のコワーキングスペース向けマッチング 利用者に仕事を紹介するコワーキング運営者は、マッチングを、 人力で行っている※が、このマッチングを行うに至る導線の創出と、 マッチングのAI・ML化をElixirのスケーラビリティと共に支援する ※そもそもこうした交流ができないコワーキングスペースも多い 北九州から国内1,000箇所+海外への展開を5年越しで行う Coworking coordinator who introduce work to users are doing matching manually, this PJ realize automation matching and path navigation to this matching with Elixir scalability and AI / ML Using 5 years from Kitakyu, expand to 1,000 locations in Japan and overseas many locations

Slide 129

Slide 129 text

128 ②LiveView+WebGLで3D画像リアルタイム解析 Phoenix LiveViewの差分更新と、WebGLによるエッジ画像 解析を組み合わせ、ドローンに搭載した360°カメラが撮影した 地形画像を、ドローン側でリアルタイム解析する Combines the difference update of Phoenix LiveView and edge image analysis by WebGL, and the terrain image taken by the 360 ° camera installed in the drone is analyzed in real time on the drone side 360°カメラ

Slide 130

Slide 130 text

129 ③小倉駅前、5Gネットワークでハイタッチサービス実現 大手キャリアが、5Gの全国適用に迷走する横を小倉駅前限定 のローカルエリア (駅前300m) で5G+Elixirで高速/低遅延 /100万台同時接続の威力を実証実験し、データ収集します A major carrier is straying for the nationwide apps of 5G. In the local area limited to the front of Kokura Station (300m in front of the station), 5G + Elixir demonstrates the power of ultra-high-speed / low-latency / one million simultaneous connections to collect data

Slide 131

Slide 131 text

130 北九州における開拓は 福岡市の3倍速で展開中 Our development in Kitakyu is being deployed at 3 times the speed of Fukuoka City

Slide 132

Slide 132 text

131 天神/小倉/沖縄/東京に拠点あり、フルリモート勤務 を実現する、国内トレンドを先行したITスタートアップです 人手不足を感じさせない前年比2倍 (32→75名) 成長 Karabiner technology inc: Operating officer

Slide 133

Slide 133 text

132 福岡市で大人気のElixir コミュニティ「fukuoka.ex」 https://fukuokaex.fun/ 2年強で33回イベント開催、 述べ1,100名もの参加者 が訪れています 福岡以外からも訪れます 海外(テキサス、コロラド) での講演を開始! Lonestar ElixirConf 2019 ElixirConf US 2019

Slide 134

Slide 134 text

133 Elixirを活用した私達の活動が、事業/アカデミックの 両側面で、短期間でグロースしている様が共有できたら、 とても嬉しいです Can you understand that our activities using Elixir grew rapidly on both sides of the business and academic? I would be very happy if you could share it これらの詳しい内容を知りたい方、休憩時間や懇親会 で私に話しかけてください (なお、海外にガンガン進出する割には、私は英会話が苦手ですw) If you want to know more about these, please talk to me at breaks and social gatherings (Although we have expanded overseas, I'm not good at speaking English)

Slide 135

Slide 135 text

134