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作成
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
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年間、プログラマと
して活動している最大の理由は、
「自ら世界を生み出せる」
という、まるで魔法のようなものに、
魅了され続けているからなのです
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コミュニティ
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
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
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
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
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
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
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)