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
Haskell-Rinko-11
Search
Sponsored
·
SiteGround - Reliable hosting with speed, security, and support you can count on.
→
Shintaro Ikeda
May 14, 2019
Technology
69
0
Share
Embed
Copy iframe code
Copy JS code
Copy link
Start on current slide
Haskell-Rinko-11
Presentation for
http://learnyouahaskell.com/a-fistful-of-monads
Shintaro Ikeda
May 14, 2019
More Decks by Shintaro Ikeda
See All by Shintaro Ikeda
Difference between Swagger and OpenAPI
momotaro98
0
190
習慣的にやりたいことを手助けしてくれるLINEボットを作った話
momotaro98
0
80
AlertForViber_20171207
momotaro98
0
260
アウトプット駆動スキルアップ
momotaro98
1
98
マイクロサービスの概要と構築 統合編
momotaro98
0
110
Other Decks in Technology
See All in Technology
AI、CDK と協働する Full TypeScript アプリケーション開発 / Full TypeScript Application with AI and CDK
geekplus_tech
2
380
SRE Next 2026 何でも屋からの脱却
bto
0
930
凡エンジニアがこの先生きのこるためには。〜TypeScript完全に理解したい〜
alchemy1115
2
310
生成AI×AWS CDK×AWS FISで"振り返れる"ミニGameDayをつくろう
yoshimi0227
1
390
最適な自走を最小限の支援で — M&Aで拡大する組織で少人数SREが挑んだ1年 / SRE NEXT 2026
genda
0
1.5k
Compose 新機能総まとめ / What's New in Jetpack Compose
yanzm
0
320
人を動かすのは時間ではなく、納得感 〜新任EMが入社3ヶ月、組織を2回変えた話〜
kakehashi
PRO
3
270
ボーイスカウトルールでメモリやスキルを改善しよう
azukiazusa1
4
1.4k
Amazon EVS で VCF 9.0 / 9.1 のサポート開始まとめ
mtoyoda
0
310
大量データに対しても、生成AIを用いてリーズナブルにデータ加工をしたい!Databricksのai_queryについて調べてみた
kamoshika
1
220
ファミコンでPHPを動かす / PHP on the Famicom
tomzoh
2
390
SRE本の知られざる名シーン / The Hidden Gems of Google SRE Book
nari_ex
1
420
Featured
See All Featured
Jess Joyce - The Pitfalls of Following Frameworks
techseoconnect
PRO
1
190
Impact Scores and Hybrid Strategies: The future of link building
tamaranovitovic
0
340
WCS-LA-2024
lcolladotor
0
710
世界の人気アプリ100個を分析して見えたペイウォール設計の心得
akihiro_kokubo
PRO
72
40k
Leveraging Curiosity to Care for An Aging Population
cassininazir
1
390
Digital Projects Gone Horribly Wrong (And the UX Pros Who Still Save the Day) - Dean Schuster
uxyall
1
2k
The World Runs on Bad Software
bkeepers
PRO
72
12k
Design and Strategy: How to Deal with People Who Don’t "Get" Design
morganepeng
133
19k
Chrome DevTools: State of the Union 2024 - Debugging React & Beyond
addyosmani
10
1.3k
How to Ace a Technical Interview
jacobian
281
24k
Max Prin - Stacking Signals: How International SEO Comes Together (And Falls Apart)
techseoconnect
PRO
0
200
Collaborative Software Design: How to facilitate domain modelling decisions
baasie
1
260
Transcript
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 1/16 CHAPTER 12 - A FISTFUL OF
MONADS CHAPTER 12 - A FISTFUL OF MONADS モナドがいっぱい モナドがいっぱい 発表者: 池田 伸太郎 2019 年5 月14 日
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 2/16 Functor → Applicative Functor → Monad
→ → モナドはアプリカティブファンクターの特徴も兼 ねた強化版
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 3/16 復習 Functor もApplicative Functor もある文脈( 箱とも言
っている) を表現する型クラス。 Eq, Ord 型クラスとは異なり、1 つ分の型引数を取 る型コンストラクタが利用対象。 , , とかはApplicative Functor だし Monad でもある。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 4/16 復習 - You Maybe remember... ああ、確かにアプリカティブ則が成り立っている
ようだな、と納得することができますね。 定義
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 5/16 復習 - リスト ああ、確かに(ry
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 6/16 モナドくんの願い モナドくんの願い 普通の値a を取って文脈付きの値を返す関数に、文 脈付きの値m a
を渡したい 言い換えると以下の関数が欲しい 関数 はバインド(bind) と呼ばれる。 モナドは をサポートするアプリカティブファ ンクターである。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 7/16 モナドくん モナドくん
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 8/16 Haskell の歴史的背景によりMonad 定義には Applicative の型クラス制約がない。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 9/16 【綱渡りの問題】 養魚場で働くピエールが休暇を取り綱渡りに挑 戦。バランス棒に鳥が止まりに来るんです。鳥た ちはちょっと休んでまたどこかへ飛んでいく。 棒の左右に止まった鳥の差が3 以内ならば、ピエー
ルはバランスが取れるがそうでないならバランス を崩して落ちてしまう。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 10/16 でも はPole 型しかとれない! と合成して書きた いときはどうすれば良い?
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 11/16 は を文脈付きのまま扱うことができ る。 このように文脈の値どうしを相互作用させること はアプリカティブファンクターにはできないこと でありモナドならば実現できる。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 12/16 もし をモナドとして扱っていなかったら... このような巨大で汚いコードを でモナド適用 の連鎖で書き直すのは、Maybe モナド布教コード
の定番。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 13/16 do 記法 いつ を使い、いつdo 記法を使うか、選択はあ なた次第です。
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 14/16 リスト([]) はモナド。リストをモナドとしての側面 を使うことで、非決定性を伴うコードをきれいに 読みやすくすることができる。 リストからすべてのパターンを尽くして非決定的 値を最終的に返す。
非決定性 性質 扱 定義
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 15/16 実は、リスト内包表記はリストモナドの糖衣構文 であった!リスト内包表記もdo 記法も、内部では を使った非決定性計算に変換される。 記法 書
2019/5/13 reveal.js file:///Users/shintaro/Dropbox/Presentation/RakutenDoki_Rinko_Haskell_11/my-reveal.js/index.html 16/16 モナド則 モナド則 【左恒等性と右恒等性】 => いずれも が通常値をモナド値に最小限な
単位で返すことを保証する法則 【結合法則】 => モナド値をモナド関数らに食わせるとき、入れ 子の順序は関係なく関数自体の意味のみが結果に 反映されるよ 詳しくは で! WEB