1 / 9

君ならどう書く - Haskell – 自由演技編

君ならどう書く - Haskell – 自由演技編. λ. 酒井 政裕. 何か面白い一発ネタをやりたかったけど ……. 思いつかなかった. orz. 期待してた人ごめん. で、何を作ったか. 仕方ないので、チャーチ数で計算させてみた 関数型言語 ~ ( 型付き ) ラムダ計算 チャーチ数 (Church Numerals) ラムダ計算での自然数の表現. ラムダ計算 : 項. 項 M,N ::= (M N) -- 関数適用 | (λx. M) -- λ 抽象

murray
Download Presentation

君ならどう書く - Haskell – 自由演技編

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. 君ならどう書く - Haskell –自由演技編 λ 酒井 政裕

  2. 何か面白い一発ネタをやりたかったけど……

  3. 思いつかなかった orz 期待してた人ごめん

  4. で、何を作ったか • 仕方ないので、チャーチ数で計算させてみた • 関数型言語 ~ (型付き)ラムダ計算 • チャーチ数 (Church Numerals) • ラムダ計算での自然数の表現

  5. ラムダ計算: 項 • 項 M,N ::= (M N) -- 関数適用 | (λx. M) -- λ抽象 | x -- 変数 • 省略記法 • 括弧を省略 • 関数適用は左結合的であるとして括弧を省略 • その他自明な括弧は省略 • 「λx. λy. M」 を「λ x y. M」と略記

  6. ラムダ計算: 簡約 • 簡約 • β変換: (λx. M) N  M[x := N] • Mの中に現れるxをNで置換 • 関数適用に対応 • 本当は名前が衝突しないようにα変換の必要がある • けど、説明するの面倒なので略 • α変換: (λx. M)  λy. M[x := y] • 束縛変数の変更 • 本当は名前が衝突しないように(ry

  7. チャーチ数 • ラムダ計算では「関数」しか存在しない! • 数も関数として表現 • 0 := λf x. x • 1 := λf x. f x • 2 := λf x. f (f x) • … • 足し算: plus := λa b. λf x. a f (b f x) • 掛け算: times := λa b. λf. a (b f) • べき乗: exp := λa b. b a

  8. 計算例 • 1+1 • (λa b f x. a f (b f x)) (λf x. f x) (λf x. f x)  (λb f x. (λf x. f x) f (b f x)) (λf x. f x) λf x. (λf x. f x) f ((λf x. f x) f x) λf x. (λx. f x) ((λf x. f x) f x) λf x. f ((λf x. f x) f x) λf x. f ((λx. f x) x) λf x. f (f x)

  9. ご清聴ありがとうございました

More Related