$30 off During Our Annual Pro Sale. View Details »
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
140
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
520
Cloud migration of the essential service
rst76
1
600
performance-tuning-of-the-microservice.pdf
rst76
0
1.6k
red-black-tree.pdf
rst76
0
91
Understanding Subtype in 5 Minutes
rst76
0
180
Fun of Types
rst76
0
54
Embedded Probabilistic Programming
rst76
0
360
Featured
See All Featured
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.6k
Building an army of robots
kneath
306
46k
Designing Experiences People Love
moore
143
24k
Keith and Marios Guide to Fast Websites
keithpitt
413
23k
Learning to Love Humans: Emotional Interface Design
aarron
274
41k
Making the Leap to Tech Lead
cromwellryan
135
9.7k
No one is an island. Learnings from fostering a developers community.
thoeni
21
3.6k
A Modern Web Designer's Workflow
chriscoyier
698
190k
Building Better People: How to give real-time feedback that sticks.
wjessup
370
20k
The Pragmatic Product Professional
lauravandoore
37
7.1k
For a Future-Friendly Web
brad_frost
180
10k
Into the Great Unknown - MozCon
thekraken
40
2.2k
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
まとめ 関数型言語は楽しいので、みんなやりましょう