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
91
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
400
Cloud migration of the essential service
rst76
1
450
performance-tuning-of-the-microservice.pdf
rst76
0
1.2k
red-black-tree.pdf
rst76
0
64
Understanding Subtype in 5 Minutes
rst76
0
130
Fun of Types
rst76
0
32
Embedded Probabilistic Programming
rst76
0
220
Featured
See All Featured
Being A Developer After 40
akosma
56
580k
Pencils Down: Stop Designing & Start Developing
hursman
115
11k
Helping Users Find Their Own Way: Creating Modern Search Experiences
danielanewman
19
1.9k
It's Worth the Effort
3n
180
27k
What’s in a name? Adding method to the madness
productmarketing
PRO
14
2.6k
Responsive Adventures: Dirty Tricks From The Dark Corners of Front-End
smashingmag
242
20k
Done Done
chrislema
178
15k
Imperfection Machines: The Place of Print at Facebook
scottboms
257
12k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
39
4.3k
Robots, Beer and Maslow
schacon
PRO
154
7.9k
Designing for Performance
lara
601
67k
The Brand Is Dead. Long Live the Brand.
mthomps
48
22k
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
まとめ 関数型言語は楽しいので、みんなやりましょう