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
·
Your Podcast. Everywhere. Effortlessly.
Share. Educate. Inspire. Entertain. You do you. We'll handle the rest.
→
Shintaro Ikeda
May 14, 2019
Technology
61
0
Share
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
180
習慣的にやりたいことを手助けしてくれるLINEボットを作った話
momotaro98
0
75
AlertForViber_20171207
momotaro98
0
250
アウトプット駆動スキルアップ
momotaro98
1
96
マイクロサービスの概要と構築 統合編
momotaro98
0
100
Other Decks in Technology
See All in Technology
Standards et agents IA : un tour d’horizon de MCP, A2A, ADK et plus encore
glaforge
0
190
20260428_Product Management Summit_Loglass_JoeHirose
loglassjoe
3
3.7k
運用システムにおけるデータ活用とPlatform
sansantech
PRO
0
120
AIを共同作業者にして書籍を執筆する方法 / How to Write a Book with AI as a Co-Creator
ama_ch
2
150
自分のハンドルは自分で握れ! ― 自分のケイパビリティを増やし、メンバーのケイパビリティ獲得を支援する ― / Take the wheel yourself
takaking22
1
960
AgentCore×VPCでの設計パターンn選と勘所
har1101
3
310
データ定義の混乱と戦う 〜 管理会計と財務会計 〜
wonohe
0
140
Do Vibe Coding ao LLM em Produção para Busca Agêntica - TDC 2026 - Summit IA - São Paulo
jpbonson
3
150
LLM時代の検索アーキテクチャと技術的意思決定
shibuiwilliam
3
1.5k
Expiration of Secure Boot Certificates for vSphere Virtual Machines
mirie_sd
0
110
Microsoft 365 / Microsoft 365 Copilot : 自分の状態を確認する「ラベル」について
taichinakamura
0
350
Good Enough Types: Heuristic Type Inference for Ruby
riseshia
1
300
Featured
See All Featured
Neural Spatial Audio Processing for Sound Field Analysis and Control
skoyamalab
0
270
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
4.2k
Skip the Path - Find Your Career Trail
mkilby
1
110
My Coaching Mixtape
mlcsv
0
110
A Tale of Four Properties
chriscoyier
163
24k
Have SEOs Ruined the Internet? - User Awareness of SEO in 2025
akashhashmi
0
320
Git: the NoSQL Database
bkeepers
PRO
432
67k
Stop Working from a Prison Cell
hatefulcrawdad
274
21k
Navigating the Design Leadership Dip - Product Design Week Design Leaders+ Conference 2024
apolaine
0
270
How to build a perfect <img>
jonoalderson
1
5.4k
Designing Powerful Visuals for Engaging Learning
tmiket
1
350
Marketing Yourself as an Engineer | Alaka | Gurzu
gurzu
0
180
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