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! ==
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
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 +
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
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
(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
前述の通り、最古の部類です 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
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
あり、コンパイルタイムに型チェックが走るため、「弱い型付け」である上記言語 が、ランタイムまで型チェックされないのとは、異なる型安全性を保持しています 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
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
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/
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
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"
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"
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)
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
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]
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]
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...
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
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)
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)
uses Maybe and monads, etc. to: ➢ 統一的なエラー処理 (unified error handling) ➢ 純粋関数により得られる参照透過性 (referential transparency gained by pure functions) ➢ 型安全な汎用関数プログラミング (Type-safe general functional programming)
➢ プログラムは人が書くものだからバグは避けられない (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)
アプリ開発で最重要なのはデータ処理とすぐに実感できる ➢ 「イミュータブル」と「シェアードナッシング」を最も学びやすい ➢ 並行/分散、耐障害性が日常になる ➢ 「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
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!!)
ほぼシーケンシャルに上昇していることを確認しています 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
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)
(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
にて 状態保持も可能で、局所的な性能改善として効果があります 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
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" ] ) %> <table border="1"> <%= for data <- datas do %> <tr> <td><%= data[ "name" ] %></td> <td><%= data[ "age" ] %></td> </tr> <% end %> </table>
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...
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
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
山崎先生が開発し、今年の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
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
地方にも関わらず、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
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
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°カメラ
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
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)