Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
About purely functional language
Search
Ryosuke TAKASHIMA
August 28, 2020
0
120
About purely functional language
Ryosuke TAKASHIMA
August 28, 2020
Tweet
Share
More Decks by Ryosuke TAKASHIMA
See All by Ryosuke TAKASHIMA
GCP native cloud migration
rst76
1
500
Cloud migration of the essential service
rst76
1
570
performance-tuning-of-the-microservice.pdf
rst76
0
1.5k
red-black-tree.pdf
rst76
0
87
Understanding Subtype in 5 Minutes
rst76
0
160
Fun of Types
rst76
0
53
Embedded Probabilistic Programming
rst76
0
340
Featured
See All Featured
Thoughts on Productivity
jonyablonski
69
4.8k
jQuery: Nuts, Bolts and Bling
dougneiner
63
7.8k
Statistics for Hackers
jakevdp
799
220k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
Rails Girls Zürich Keynote
gr2m
95
14k
Cheating the UX When There Is Nothing More to Optimize - PixelPioneers
stephaniewalter
283
13k
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
47
9.6k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
656
60k
The Language of Interfaces
destraynor
158
25k
Visualization
eitanlees
146
16k
Done Done
chrislema
184
16k
The Success of Rails: Ensuring Growth for the Next 100 Years
eileencodes
45
7.5k
Transcript
純粋関数型言語の話
自己紹介 • 高島 亮祐(@rst76) • エムスリー 基盤チーム(2019/01-) • 推してるマンガ: チェンソーマン、宝石の国、ゴールデンゴールド •
推してる◦◦映画:デビルマン実写版(116分) • 今日は純粋関数型言語の布教活動をします
Simple か Easy か • Simple ⇔ Complex • Easy
⇔ Difficult • Simple で Easy なら理想的だが・・・ • Easy を指向しているもの: Java の Annotation、Python のライブラリ群 • 個人的には Simple を優先したい → Haskell、Lazy K、F#
ラムダ計算 • プログラム = データ + プロセス(メソッド/関数) • データだけでプログラムを実現することはできないが、 プロセスだけで実現することはできる
• データをプロセス(関数)で表現 = ラムダ計算 • プログラムが扱う対象が1つだけになる(Simple!) データ プロセス データ
ラムダ計算でのデータ型(1) • Numeric ◦ 0 = \f x -> x
◦ 1 = \f x -> f x ◦ 2 = \f x -> f (f x) ◦ f = (+ 1), x = 0 と考えると分かりやすい • Boolean ◦ true = \x y -> x ◦ false = \x y -> y
ラムダ計算でのデータ型(2) • List ◦ cons = \x y f ->
f x y ◦ car = \z -> z true car (cons x y) = cons x y true = true x y = x ◦ cdr = \z -> z false cdr (cons x y) = cons x y false = false x y = y • 文字列を数字のリストと捉えれば、文字列も扱える
コンビネータ • よく使う関数に名前をつける • 恒等関数 I = \x -> x •
関数合成 B = \f g x -> f (g x) • 引数交換 C = \f x y -> f y x • 破棄 K = \x y -> x • 複製 W = \f x -> f x x
コンビネータを組み合わせる • true = \x y -> x = K
• false = \x y -> y = CK • 0 = \f x -> x = CK • 1 = \f x -> f x = I • 2 = \f x -> f (f x) = WB その他の関数もコンビネータを組み合わせて実現できる
コンビネータを組み合わせる • C K x y = (\f a b
-> f b a) K x y = K y x = (\a b -> a) y x = y • 0 x y = (\f a -> a) x y = y
SK コンビネータ • S = \x y z -> x
z (y z) • K = \x y -> x • S と K ですべてのコンビネータを表現できる(Simple!) (実はコンビネータは1つで十分 → Iota)
I = S K K • S K K x
= (K x) (K x) = K x (K x) = x = I x S = \x y z -> x z (y z) K = \x y -> x
B = S (K S) K • S (K S)
K f g x = (K S) f (K f) g x = K S f (K f) g x = S (K f) g x = (K f) x (g x) = K f x (g x) = f (g x) = B f g x S = \x y z -> x z (y z) K = \x y -> x
SK で表す数(デモ) • 0 = SK • 1 = SKK
• 2 = SS(SK)(S(KS)K) • 3 = SS(SS(SK))(S(KS)K) • 8 = 3 2 = SS(SS(SK))(S(KS)K)(SS(SK)(S(KS)K)) https://codepen.io/rst76/pen/BaKLjVN
まとめ 関数型言語は楽しいので、みんなやりましょう