Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.

Functional Pearl + Brainfuck

785 views

Published on

HaskellでBrainfuckインタプリタを作ったことについて、初心者向け

  • DOWNLOAD THI5 BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download Full EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download EPUB Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... Download doc Ebook here { http://bit.ly/2m6jJ5M } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • DOWNLOAD THIS BOOKS INTO AVAILABLE FORMAT (Unlimited) ......................................................................................................................... ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download Full EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ACCESS WEBSITE for All Ebooks ......................................................................................................................... Download Full PDF EBOOK here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download EPUB Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... Download doc Ebook here { https://tinyurl.com/y6a5rkg5 } ......................................................................................................................... ......................................................................................................................... ......................................................................................................................... .............. Browse by Genre Available eBooks ......................................................................................................................... Art, Biography, Business, Chick Lit, Children's, Christian, Classics, Comics, Contemporary, Cookbooks, Crime, Ebooks, Fantasy, Fiction, Graphic Novels, Historical Fiction, History, Horror, Humor And Comedy, Manga, Memoir, Music, Mystery, Non Fiction, Paranormal, Philosophy, Poetry, Psychology, Religion, Romance, Science, Science Fiction, Self Help, Suspense, Spirituality, Sports, Thriller, Travel, Young Adult,
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here

Functional Pearl + Brainfuck

  1. 1. FUNCTIONAL PEARL + BRAINFUCK 67th yingtai
  2. 2. 自己紹介• yingtai• 67回生 (高1)• twitter: @__int• Haskellが好き
  3. 3. 何してたか• brainfuckのインタプリタを作ってました • Haskell製• variantも作りたかったです
  4. 4. BRAINFUCKとは• ググれ • Wikipediaの記事読めば分かります• (闇の|難解)プログラミング言語
  5. 5. HELLO, WORLD>+++++++++[<++++++++>-]<.>+++++++[<++++>-]<+.+++++++..+++.[-]>++++++++[<++++>-]<.>+++++++++++[<+++++>-]<.>++++++++[<+++>-]<.+++.------.--------.[-]>+++++++ +[<++++>-]<+.[-]++++++++++.
  6. 6. インタプリタとは• ソースコードを実行するソフトウェア
  7. 7. HASKELLとは• 光のプログラミング言語• 純粋関数型
  8. 8. LTでしたいこと• 成果発表• Haskellのかんたんな説明• たぶん LT じゃなくなります
  9. 9. 処理の流れ source code parse AST execute I/O
  10. 10. かいせつ 文字列として 読み込むsource code parse AST execute I/O
  11. 11. かいせつsource code データを整形 (実行しやすく) parse AST execute I/O
  12. 12. かいせつ source code データを整形Parsec (実行しやすく) parse AST execute I/O
  13. 13. かいせつsource code parse データ、木構造 AST execute I/O
  14. 14. かいせつsource code parse データ、木構造 AST execute I/O
  15. 15. かいせつsource code parse AST 実行! execute I/O
  16. 16. かいせつsource code parse AST execute 外に入出力される I/O
  17. 17. ところで
  18. 18. ところで source code parse• 「Haskellは純粋関数型」 AST• どういう意味? execute I/O
  19. 19. 純粋関数とは• 「副作用を及ぼさない関数」のこと• 副作用とは?• おおざっぱに説明します
  20. 20. 副作用とは• int power (int x) {return x * x;} • これは副作用がない• int power2 (int x) {printf(“hoge”); return x * x;} • これには副作用がある
  21. 21. 副作用とは• int power2 (int x) {printf(“hoge”); return x * x;} • hoge と外部に出力している • これは返す値には関係がない!
  22. 22. たとえば int main() { int x = power2(5); printf(“%d¥n”, x);• 右のコードを動かす }• 関数の使用者が単に 5^2 を計算したいだけなら?•→ hoge の表示は計算に「無関係な作用」である
  23. 23. ここで問題です int main() {• 右のmain関数において int x = power(5); printf(“%d¥n”, x);• 「副作用」は存在するか? }
  24. 24. あります int main() { int x = power(5); printf(“%d¥n”, x);• 計算結果を表示してる }•→ main関数が「外」の状態を変更している
  25. 25. なくしたければ int main() {• こうすればいい! int x = power(5); }• 外部の状態を変更しない• (無意味)
  26. 26. つまり• 副作用はどうしても必要なもの• だけど「純粋関数」に副作用はあってほしくない• → うまく分離すればいい!
  27. 27. ここで問題です source code parse• 右の過程において AST• 「副作用」のある部分は? execute I/O
  28. 28. source code parse AST execute I/O
  29. 29. ANSWER source code parse• 答えは右図 AST execute I/O
  30. 30. 「分離」 source code• Haskellには「IOモナド」と parseいう概念がある AST• ここでは「箱」としてイ executeメージしてください I/O
  31. 31. 「分離」 source code parse• 非純粋な関数を隔離する AST•→ IOモナドという箱に入れる IO Monad execute I/O
  32. 32. 「分離」 source code parse• 副作用は箱の外には及ばな ASTい! IO Monad execute I/O
  33. 33. 閑話休題
  34. 34. 成果報告します• brainfuckインタプリタを作りました (再掲)• https://gist.github.com/gists/3318876/
  35. 35. なぜ作ったか• Haskellで書いたことがなかった• 特に Zipper の練習
  36. 36. ZIPPERとは• Functional Pearl の一つ• すごいH本の最終章でも紹介されてます
  37. 37. ZIPPERとは• 木構造を手続き型的に簡単に扱うパターン• ポインタ / メモリ、 命令 / コード をzipする
  38. 38. 例えば• [0, 1, 2, 3, 4, 5, 6, 7, 8, 9] というリスト、ポインタは 7•→ ([6, 5, 4, 3, 2, 1, 0], [7, 8, 9])• リスト = ジッパー, ポインタ = チャック
  39. 39. BRAINFUCKでは• 直線的に命令が実行されていく• ループがある•→ 2分木• ループ部分で枝分かれ
  40. 40. 結果• brainfuckなのにS式みたいになります• evalします• まわりくどいです
  41. 41. まとめ• インタプリタはparseしexecuteする• 副作用は「外の状態を変更する」作用• Haskellは光の言語 • だがBrainfuckインタプリタの作成には不向き
  42. 42. ご清聴ありがとうございました

×