$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Haskell-Rinko-11
Search
Shintaro Ikeda
May 14, 2019
Technology
0
46
Haskell-Rinko-11
Presentation for
http://learnyouahaskell.com/a-fistful-of-monads
Shintaro Ikeda
May 14, 2019
Tweet
Share
More Decks by Shintaro Ikeda
See All by Shintaro Ikeda
Difference between Swagger and OpenAPI
momotaro98
0
160
習慣的にやりたいことを手助けしてくれるLINEボットを作った話
momotaro98
0
67
AlertForViber_20171207
momotaro98
0
230
アウトプット駆動スキルアップ
momotaro98
1
78
マイクロサービスの概要と構築 統合編
momotaro98
0
89
Other Decks in Technology
See All in Technology
[2025-12-12]あの日僕が見た胡蝶の夢 〜人の夢は終わらねェ AIによるパフォーマンスチューニングのすゝめ〜
tosite
0
170
M&Aで拡大し続けるGENDAのデータ活用を促すためのDatabricks権限管理 / AEON TECH HUB #22
genda
0
230
20251218_AIを活用した開発生産性向上の全社的な取り組みの進め方について / How to proceed with company-wide initiatives to improve development productivity using AI
yayoi_dd
0
650
Bedrock AgentCore Memoryの新機能 (Episode) を試してみた / try Bedrock AgentCore Memory Episodic functionarity
hoshi7_n
2
1.8k
[Data & AI Summit '25 Fall] AIでデータ活用を進化させる!Google Cloudで作るデータ活用の未来
kirimaru
0
3.8k
Amazon Quick Suite で始める手軽な AI エージェント
shimy
1
1.8k
[Neurogica] 採用ポジション/ Recruitment Position
neurogica
1
120
Strands AgentsとNova 2 SonicでS2Sを実践してみた
yama3133
1
1.8k
Bedrock AgentCore Evaluationsで学ぶLLM as a judge入門
shichijoyuhi
2
240
NIKKEI Tech Talk #41: セキュア・バイ・デザインからクラウド管理を考える
sekido
PRO
0
210
JEDAI認定プログラム JEDAI Order 2026 エントリーのご案内 / JEDAI Order 2026 Entry
databricksjapan
0
180
AR Guitar: Expanding Guitar Performance from a Live House to Urban Space
ekito_station
0
150
Featured
See All Featured
New Earth Scene 8
popppiees
0
1.2k
Darren the Foodie - Storyboard
khoart
PRO
0
1.9k
Navigating Algorithm Shifts & AI Overviews - #SMXNext
aleyda
0
1k
Everyday Curiosity
cassininazir
0
110
JAMstack: Web Apps at Ludicrous Speed - All Things Open 2022
reverentgeek
1
290
From π to Pie charts
rasagy
0
91
Chasing Engaging Ingredients in Design
codingconduct
0
84
We Analyzed 250 Million AI Search Results: Here's What I Found
joshbly
0
260
Practical Orchestrator
shlominoach
190
11k
Exploring the Power of Turbo Streams & Action Cable | RailsConf2023
kevinliebholz
37
6.2k
Leadership Guide Workshop - DevTernity 2021
reverentgeek
0
170
Bash Introduction
62gerente
615
210k
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