SlideShare a Scribd company logo
1 of 55
Download to read offline
ゆるふわなHaskell話
@ruicc
13年6月23日日曜日
誰
@ruicc
Haskeller
13年6月23日日曜日
ゆるふわな話
IOの話
13年6月23日日曜日
IOの話
13年6月23日日曜日
よく聞きそうな話
「HaskellはIO実行が簡単に出来な
い、つらい」
13年6月23日日曜日
Haskeller視点
「大抵の言語はIOがいつでもどこでも
実行出来てしまって危険極まりない、
つらい」
13年6月23日日曜日
それを聞いた非Haskeller
Haskellは副作用使用罪がある!
コワイ!
僕:それは怖いねー(棒読み)
13年6月23日日曜日
もう少し詳しく見る
「HaskellはIO実行が簡単に出来な
い、(ちょっとしたスクリプト感覚で
書けなくて)つらい」
13年6月23日日曜日
もう少し詳しく見る
「大抵の言語はIOがいつでもどこでも
実行出来てしまって危険極まりない、
(チーム開発時やコードの保守やコー
ドの再利用性が無くて)つらい」
13年6月23日日曜日
要は見ている問題が違う
全ての言語への言及は「適材適所」を
詳しく語ったもの
13年6月23日日曜日
以降
ゆるふわな心で
お楽しみください。
13年6月23日日曜日
IOの何が問題なのか?
IO実行を書く事は
プログラムに「制御不可能なコード」
を埋め込むこと
13年6月23日日曜日
例えば現在時刻の取得
現在時刻取得はIO実行
リアルワールドの参照
time = getTime(); // IO発生!!
13年6月23日日曜日
例えば現在時刻の取得
関数の中で現在時刻を取得してみる
var f = function doSomething() {
var time = getTime(); // IO!!
// do something...
}
➡ リアルワールドの現在時刻に依存した!!!
➡ 制御不可能な値に依存する関数は筋が悪い
13年6月23日日曜日
制御不可能な関数
IOが含まれる制御不可能な関数
テストがつらい
再利用時につらい
保守がつらい
13年6月23日日曜日
じゃあどうする
シングルトンパターンを使うよ!
えっ
13年6月23日日曜日
シングルトンパターン
シングルトンという名のグローバル変数
グローバル変数に依存した関数
テストがつらい
再利用時につらい
保守がつらい
13年6月23日日曜日
じゃあどうする
RubyならOpen classで出来るよ!
えっと
13年6月23日日曜日
それXXX言語ならできるよ
言語依存の機能
まあいいんですけど
いいんですよ
何も問題は無い...その言語なら。
13年6月23日日曜日
もっと一般的に問題を解く
開発サーバの実行時間変えるよ!
はい
13年6月23日日曜日
言語の外を触る
言語からは制御出来ない、言語の外の
部分を変更する
人間がナニカを保証する必要がある
テストが終わったら元に戻す
他に影響を出さない
保守対象が増える
13年6月23日日曜日
言語内で問題を解く
関数の外部でIO実行、引数で渡す
var f = function doSomething(time) {
// do something...
}
➡ IOは発生しない
➡ 安全!再利用しやすい!保守しやすい!
13年6月23日日曜日
引数渡しは何か問題が?
引数を引き回す事はあまり問題ではない
テスト可能性が低下するよりマシ
保守性が低下するよりマシ
再利用性が低下するよりマシ
13年6月23日日曜日
IOは隔離する
引数引き回しはともかく、
IO実行部分は隔離することが望ましい
言語によらない
13年6月23日日曜日
IOと設計
getTimeを例に考えてきた
制御不能部分を考えることは、設計行為
➡ IOを考える事は、設計行為
13年6月23日日曜日
おまけ
引数を一つ増やす?
そうですねいろんな所が増えそうですね
13年6月23日日曜日
引数引き回しはダサいか
引数引き回しがダサいという風潮
...がある気がする
意味がわからないよ!
ダサさの前に問題を解こうぜ
13年6月23日日曜日
引数引き回し問題
それが問題になるなら問題を解こう
引数引き回し問題は、IOとは別問題
Readerモナモナ
ここでは触れません
13年6月23日日曜日
まとめ:IOとは
どんな言語でも、
大抵のプログラムでは、
設計上、
隔離するべきもの
HaskellはIOを型で検知するに過ぎない
13年6月23日日曜日
IOが隔離不可能な場合
IOの隔離が出来ない場合はどうする?
13年6月23日日曜日
次の問題
IOと切り離せないドメインはどうする
Graphics
Sounds
GUI
REPL
13年6月23日日曜日
素直に書く
全ての関数IO直書きするよ!
ふむ
13年6月23日日曜日
IO直書き
IOがいつ何処で発生するか分からない
他の言語と変わらない
13年6月23日日曜日
つまり
D4Cが発生する
まちがいない
13年6月23日日曜日
D4C
いともたやすく行われるえげつない行為
dirtyDeedsDoneDirtCheap :: IO President
チーム開発中に能力が発現
よくわからないところにありえないコードが
埋没している
保守を壊滅的にしてくれる
13年6月23日日曜日
D4Cは防がねばならない
13年6月23日日曜日
自分でコンテキスト作成
Monad TransformerでIOくるむよ!
えーと
13年6月23日日曜日
モナド変換子
liftIOで結局IO使い放題
いつIOが起こるか分からない!
newtype MyIO a = MyIO { runMyIO :: IO a }
deriving (Functor, Monad, MonadIO)
main = runMyIO $ do
myPutStrLn “Hello, MyWorld!”
liftIO $ dirtyDeedsDoneDirtCheap -- D4C
13年6月23日日曜日
モナド変換子では
D4Cは防げない
13年6月23日日曜日
Symantics...
特定のアクションを束ねるよ!
Symanticsは詳しく知らないが..
Symantcs = Syntax + Semantics
13年6月23日日曜日
SymanticsとIO
結局副作用にはIOモナドが要る
注:元々SymanticsはIOをなんとかするものではない
composedAction :: Monad m => Database m -> m ()
composedAction db = do
insert db "foo"
insert db "bar"
dirtyDeedsDoneDirtCheap -- D4C
http://mizondev.net/d/20130420
13年6月23日日曜日
やはり
D4Cは防げない
13年6月23日日曜日
Free Monadを使う
Free Monad
DSLが簡単に生成出来るモナド
プログラムを表現と解釈に分離
13年6月23日日曜日
Free Monad as a Limited IO!
Freeを制限されたIOとして使う
安全!
ゆるふわ!
D4Cから守られたコンテクスト!
モナド!
お馴染みの書き方で書ける
13年6月23日日曜日
まとめ: IOは制限する
IOは制限し、必要な箇所で必要な分量
だけ使う
言語によらないはずだが..
13年6月23日日曜日
IOを制限出来る言語
Haskell
Agda
Idris
➡要するにHaskell
13年6月23日日曜日
初めの発言
「HaskellはIO実行が簡単に出来な
い、つらい」
13年6月23日日曜日
なにHaskellはIOが厳しい?
逆に考えるんだ
「他にIOをまともに扱う
 言語が存在しないんだ」
と考えるんだ
13年6月23日日曜日
いや本当にIOをコントロール出来ない
言語ばかりなの何故ですかね
Haskellerが抱く
13年6月23日日曜日
IO Monadは
悪なのか?
13年6月23日日曜日
IO Monad
IO Monadは悪という風潮
...がある気がする
気持ちはわからなくはない
13年6月23日日曜日
他言語とIO
他言語では常にIOコンテキスト下
HaskellをIOだけで書いても
Scala,OCaml,F#と同程度の安全性
13年6月23日日曜日
私見
必要であればIOモナドにガリガリ書い
てもいいと思いますよ。
13年6月23日日曜日
まとめ:IOとは
どんな言語でも
制御されるべきもの
しかしそれが可能な言語は何故か少ない
13年6月23日日曜日
ゆるふわなHaskell話でした。
13年6月23日日曜日

More Related Content

Recently uploaded

IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxIoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxAtomu Hidaka
 
20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directoryosamut
 
プレイマットのパターン生成支援ツール
プレイマットのパターン生成支援ツールプレイマットのパターン生成支援ツール
プレイマットのパターン生成支援ツールsugiuralab
 
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
新人研修のまとめ       2024/04/12の勉強会で発表されたものです。新人研修のまとめ       2024/04/12の勉強会で発表されたものです。
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。iPride Co., Ltd.
 
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。iPride Co., Ltd.
 
プレイマットのパターン生成支援ツールの評価
プレイマットのパターン生成支援ツールの評価プレイマットのパターン生成支援ツールの評価
プレイマットのパターン生成支援ツールの評価sugiuralab
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Danieldanielhu54
 
PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000Shota Ito
 

Recently uploaded (8)

IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptxIoT in the era of generative AI, Thanks IoT ALGYAN.pptx
IoT in the era of generative AI, Thanks IoT ALGYAN.pptx
 
20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory20240412_HCCJP での Windows Server 2025 Active Directory
20240412_HCCJP での Windows Server 2025 Active Directory
 
プレイマットのパターン生成支援ツール
プレイマットのパターン生成支援ツールプレイマットのパターン生成支援ツール
プレイマットのパターン生成支援ツール
 
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
新人研修のまとめ       2024/04/12の勉強会で発表されたものです。新人研修のまとめ       2024/04/12の勉強会で発表されたものです。
新人研修のまとめ 2024/04/12の勉強会で発表されたものです。
 
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
Amazon SES を勉強してみる その12024/04/12の勉強会で発表されたものです。
 
プレイマットのパターン生成支援ツールの評価
プレイマットのパターン生成支援ツールの評価プレイマットのパターン生成支援ツールの評価
プレイマットのパターン生成支援ツールの評価
 
Postman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By DanielPostman LT Fukuoka_Quick Prototype_By Daniel
Postman LT Fukuoka_Quick Prototype_By Daniel
 
PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000PHP-Conference-Odawara-2024-04-000000000
PHP-Conference-Odawara-2024-04-000000000
 

Featured

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by HubspotMarius Sescu
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTExpeed Software
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsPixeldarts
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthThinkNow
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfmarketingartwork
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024Neil Kimberley
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)contently
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024Albert Qian
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsKurio // The Social Media Age(ncy)
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Search Engine Journal
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summarySpeakerHub
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next Tessa Mero
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentLily Ray
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best PracticesVit Horky
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project managementMindGenius
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...RachelPearson36
 

Featured (20)

2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot2024 State of Marketing Report – by Hubspot
2024 State of Marketing Report – by Hubspot
 
Everything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPTEverything You Need To Know About ChatGPT
Everything You Need To Know About ChatGPT
 
Product Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage EngineeringsProduct Design Trends in 2024 | Teenage Engineerings
Product Design Trends in 2024 | Teenage Engineerings
 
How Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental HealthHow Race, Age and Gender Shape Attitudes Towards Mental Health
How Race, Age and Gender Shape Attitudes Towards Mental Health
 
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdfAI Trends in Creative Operations 2024 by Artwork Flow.pdf
AI Trends in Creative Operations 2024 by Artwork Flow.pdf
 
Skeleton Culture Code
Skeleton Culture CodeSkeleton Culture Code
Skeleton Culture Code
 
PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024PEPSICO Presentation to CAGNY Conference Feb 2024
PEPSICO Presentation to CAGNY Conference Feb 2024
 
Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)Content Methodology: A Best Practices Report (Webinar)
Content Methodology: A Best Practices Report (Webinar)
 
How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024How to Prepare For a Successful Job Search for 2024
How to Prepare For a Successful Job Search for 2024
 
Social Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie InsightsSocial Media Marketing Trends 2024 // The Global Indie Insights
Social Media Marketing Trends 2024 // The Global Indie Insights
 
Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024Trends In Paid Search: Navigating The Digital Landscape In 2024
Trends In Paid Search: Navigating The Digital Landscape In 2024
 
5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary5 Public speaking tips from TED - Visualized summary
5 Public speaking tips from TED - Visualized summary
 
ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd ChatGPT and the Future of Work - Clark Boyd
ChatGPT and the Future of Work - Clark Boyd
 
Getting into the tech field. what next
Getting into the tech field. what next Getting into the tech field. what next
Getting into the tech field. what next
 
Google's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search IntentGoogle's Just Not That Into You: Understanding Core Updates & Search Intent
Google's Just Not That Into You: Understanding Core Updates & Search Intent
 
How to have difficult conversations
How to have difficult conversations How to have difficult conversations
How to have difficult conversations
 
Introduction to Data Science
Introduction to Data ScienceIntroduction to Data Science
Introduction to Data Science
 
Time Management & Productivity - Best Practices
Time Management & Productivity -  Best PracticesTime Management & Productivity -  Best Practices
Time Management & Productivity - Best Practices
 
The six step guide to practical project management
The six step guide to practical project managementThe six step guide to practical project management
The six step guide to practical project management
 
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
Beginners Guide to TikTok for Search - Rachel Pearson - We are Tilt __ Bright...
 

ゆるふわなHaskell話