Upgrade to Pro
— share decks privately, control downloads, hide ads and more …
Speaker Deck
Sign up for free
Menu
Search
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Features
All features
Private URLs
Password Protection
Custom URLS
Scheduled publishing
Remove Branding
Restrict embedding
Deck Collections
Notes
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Explore
Featured decks
Featured speakers
Programming
Technology
Storyboards
Pricing
Search
Sign in
Sign up for free
自作ラムダ計算インタプリタで不動点演算をする
Search
Sponsored
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Arata Sato
August 30, 2021
Programming
140
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
自作ラムダ計算インタプリタで不動点演算をする
https://github.com/atrn0/lambda
Arata Sato
August 30, 2021
More Decks by Arata Sato
See All by Arata Sato
Flutterでやっていくアプリケーション開発
atrn0
0
1.1k
Other Decks in Programming
See All in Programming
ChromeでローカルLLM
ryu1013
0
200
TanStack Vue Query と Pinia Colada から学ぶ非同期状態の型設計
aoshi
0
620
Next.js: The final boss of Web Performance
guaca
0
380
あなたの await、OS まで届いてる? strace で覗く JavaScript の非同期
hasutosasaki
1
2.2k
TS 7.0 で baseUrl が使えなくなった今、パスエイリアスをどうするか
bicstone
2
550
AI時代のTerminal環境を UNIX哲学で設計・運用する
yasunori0418
1
350
FactoryBotをやめればRSpecは速くなるのか?
yuta_onishi_97
0
1.6k
조합이폭발하는디자인시스템이걸눈으로도테스트하라고요
giljongyu
0
730
AIが実装を担う時代の「技術設計」と「チームマネジメント」
kamina_zzz
2
220
高橋メソッドでCVE解説シリーズ 〜CVE-2026-112816〜
hakkadaikon
0
230
PumaからFalconに移行したRailsアプリケーションでの実践
falcon8823
0
360
Spec-Driven Development - Why Vaadin Is the Perfect Fit
simas
PRO
0
240
Featured
See All Featured
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
1
1.7k
Exploring the relationship between traditional SERPs and Gen AI search
raygrieselhuber
PRO
4
4.4k
Templates, Plugins, & Blocks: Oh My! Creating the theme that thinks of everything
marktimemedia
31
2.9k
DevOps and Value Stream Thinking: Enabling flow, efficiency and business value
helenjbeal
2
430
How Software Deployment tools have changed in the past 20 years
geshan
3
35k
Let's Do A Bunch of Simple Stuff to Make Websites Faster
chriscoyier
508
140k
SEO for Brand Visibility & Recognition
aleyda
0
4.9k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
35
2.9k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
659
62k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
1
420
Context Engineering - Making Every Token Count
addyosmani
9
1.3k
Ruling the World: When Life Gets Gamed
codingconduct
0
430
Transcript
自作ラムダ計算インタプリタで 不動点演算をする CAMPHOR- 定例LT @atrn0
(単純型無し)ラムダ計算とは - 関数の作成と関数の適用のみからなる計算モデル - これだけでチューリング完全 - シンタックスはこんな感じ
言語の定義 文法(シンタックス)と意味(セマンティクス)を決める
シンタックス - 関数適用は左結合: s t u = (s t) u
- 適当にかっこはつけて良い - 変数のスコープはその関数の本体
セマンティクス (λx. s) t という形が来たら、sの中に出てくるxをtで置き換える(簡約) 例えば (λx.x) ((λx.x) (λz. (λx.x)
z)) → (λx. x) (λz. ((λx. x) z)) → (λz. ((λx. x) z)) → (λz. z)
目標: nの階乗を求めたい f(0) = 1 f(n) = f(n-1) * n
必要なもの: - 条件分岐 - 数 - 掛け算 - 再帰
複数引数 複数の引数は高階関数(関数を返す関数)で表す λx. λy. s つまり λx. (λy. s) *任意の複数引数の関数はカリー化によって高階関数に変換できる
Boolean - プリミティブな定数がない代わりにエンコードで表す - Booleanは true = λt. λf. t
false = λt. λf. f とエンコードする - 条件分岐は次のように書けたりする λl. λm. λn. l m n
Number c0 = λs. λz. z c1 = λs. λz.
s z c2 = λs. λz. s (s z) c3 = λs. λz. s (s (s z)) etc. - 例えば加算は λm. λn. λs. λz. m s (n s z) と書けたりする
再帰演算 不動点コンビネータを使う - 不動点コンビネータ: F g → g (F g)
となるようなFのこと。 g = λf. <fを含む本体> とすると、 F g x → g (F g) x より、<fを含む本体>でgを複製して繰り返し使える。
Yコンビネータ 不動点コンビネータの一つ Y = λf. (λx. f (x x)) (λx.
f (x x))
階乗の計算 f(0) = 1 f(n) = f(n-1) * n 必要なもの:
- 条件分岐: test = λl. λm. λn. l m n - 数: c2 = λs. λz. s (s z) など - 掛け算: times = λm. λn. m (plus n) c0 - 再帰: 不動点コンビネータ
階乗の計算 このぐらいマクロを定義するとできます。
デモ g = λf. λn. test (iszro n) (λx. c1)
(λx. (times n (f (prd n)))) c0 (fix g) cn → g (fix g) cn = (λf. λn. test (iszro n) (λx. c1) (λx. (times n (f (prd n)))) c0) (fix g) cn → test (iszro cn) (λx. c1) (λx. (times cn ((fix g) (prd cn)))) c0 ...
参考 - Types and Programming Languages (https://www.cis.upenn.edu/~bcpierce/tapl/)