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
560
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
52
Embedded Probabilistic Programming
rst76
0
330
Featured
See All Featured
Optimising Largest Contentful Paint
csswizardry
37
3.3k
The Web Performance Landscape in 2024 [PerfNow 2024]
tammyeverts
8
680
The Language of Interfaces
destraynor
158
25k
[Rails World 2023 - Day 1 Closing Keynote] - The Magic of Rails
eileencodes
35
2.4k
Creating an realtime collaboration tool: Agile Flush - .NET Oxford
marcduiker
30
2.1k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.4k
It's Worth the Effort
3n
185
28k
個人開発の失敗を避けるイケてる考え方 / tips for indie hackers
panda_program
107
19k
Intergalactic Javascript Robots from Outer Space
tanoku
271
27k
The Power of CSS Pseudo Elements
geoffreycrofte
77
5.8k
Product Roadmaps are Hard
iamctodd
PRO
54
11k
Site-Speed That Sticks
csswizardry
10
670
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
まとめ 関数型言語は楽しいので、みんなやりましょう