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
Scala の Future と Haskell の IO
Search
daimatz
May 11, 2014
Technology
4
2k
Scala の Future と Haskell の IO
daimatz
May 11, 2014
Tweet
Share
More Decks by daimatz
See All by daimatz
Ad Serving System
daimatz
0
1.1k
Dependency Injection からモックライブラリまで
daimatz
4
2.1k
TaPL 読書会 20. Recursive Types
daimatz
3
210
TaPL 読書会 15. Subtyping
daimatz
0
240
Other Decks in Technology
See All in Technology
標準技術と独自システムで作る「つらくない」SaaS アカウント管理 / Effortless SaaS Account Management with Standard Technologies & Custom Systems
yuyatakeyama
3
1.3k
BrainPadプログラミングコンテスト記念LT会2025_社内イベント&問題解説
brainpadpr
1
170
エンジニア向け技術スタック情報
kauche
1
280
低レイヤを知りたいPHPerのためのCコンパイラ作成入門 完全版 / Building a C Compiler for PHPers Who Want to Dive into Low-Level Programming - Expanded
tomzoh
4
3.3k
なぜ私はいま、ここにいるのか? #もがく中堅デザイナー #プロダクトデザイナー
bengo4com
0
480
生成AI活用の組織格差を解消する 〜ビジネス職のCursor導入が開発効率に与えた好循環〜 / Closing the Organizational Gap in AI Adoption
upamune
5
3.9k
AIとともに進化するエンジニアリング / Engineering-Evolving-with-AI_final.pdf
lycorptech_jp
PRO
0
110
生成AI時代の開発組織・技術・プロセス 〜 ログラスの挑戦と考察 〜
itohiro73
1
290
監視のこれまでとこれから/sakura monitoring seminar 2025
fujiwara3
11
4k
「良さそう」と「とても良い」の間には 「良さそうだがホンマか」がたくさんある / 2025.07.01 LLM品質Night
smiyawaki0820
1
280
Navigation3でViewModelにデータを渡す方法
mikanichinose
0
220
Welcome to the LLM Club
koic
0
190
Featured
See All Featured
Designing for Performance
lara
609
69k
Measuring & Analyzing Core Web Vitals
bluesmoon
7
490
The Psychology of Web Performance [Beyond Tellerrand 2023]
tammyeverts
48
2.8k
Automating Front-end Workflow
addyosmani
1370
200k
Agile that works and the tools we love
rasmusluckow
329
21k
Facilitating Awesome Meetings
lara
54
6.4k
4 Signs Your Business is Dying
shpigford
184
22k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
5
230
Put a Button on it: Removing Barriers to Going Fast.
kastner
60
3.9k
Fashionably flexible responsive web design (full day workshop)
malarkey
407
66k
The World Runs on Bad Software
bkeepers
PRO
69
11k
Building a Scalable Design System with Sketch
lauravandoore
462
33k
Transcript
Scala ͷ Future ͱ Haskell ͷ IO 2014-05-11 (Sun) ؔܕLTେձ
@daimatz
୭ • @daimatz • Dennoo, Inc. • Scala ͰΞυαʔόΛॻ͍͍ͯ·͢ •
Haskell ྺ 2ɺ Scala ྺ ͘Β͍
Scala ͷ Future ͱ Haskell ͷ IO ࣅ͍ͯΔ ݴ͍͍ͨ͜ͱ͜Ε͚ͩ
Future ͱ • ඇಉظܭࢉͷϞσϧ • ֓೦ࣗମ Promise ͱ͍͏ • Future
ΛݺͿͱඇಉظͰܭࢉ͕Δ • ίʔϧόοΫؔΛొ͢Δ͜ͱͰͦͷܭࢉ͕ऴΘͬ ͨ͋ͱͷڍಈΛ੍ޚ͢Δ
Future ྫ val f: Future[List[String]] = session.getRecentPosts" ! f.respond {"
case Return(posts) =>" for (post <- posts) println(post)" case Throw(throwable) =>" println(“error:” + throwable.getMessage)" } • Twitter ൛ͷྫɻ Scala ඪ४൛Ͱ໊લҧ͏͕ େମಉ͡
Scala Ͱ͏ओͳ Future ࣮ • com.twitter.util.Future" • Twitter ʹΑΔ࣮ɺ Finagle
ͱ͔ • scala.concurrent.Future" • Scala 2.10 Ͱඪ४ʹೖͬͨɺ Akka ͱ͔ • java.util.concurrent.Future" • Java ඪ४ͷ࣮ɺ Netty ͱ͔
Scala ͷ Future ͱ Haskell ͷ IO ࣅ͍ͯΔ • Scala
ͷ Future ɺ Haskell ͷ IO ͱಉ͡Α͏ͳ ײ֮Ͱ͑ΔɻݟͨΑ͘ࣅ͍ͯΔɻ • ܕͰΘ͔Δ • ϞφυͰ͋Δ • ېஅͷຐ๏͕͋Δ
ܕͰΘ͔Δ • def foo(x: String): Future[Int]" • ඇಉظܭࢉ͕ߦΘΕΔ͜ͱΛ Future[A] Ͱද͢
• bar :: String -> IO Int" • ෭࡞༻ͷ͋ΔܭࢉͰ͋Δ͜ͱΛ IO a Ͱද͢
ϞφυͰ͋Δ • for { a <- someFutureFunction() b <- otherFutureFunction(a)
} yield b" • do a <- someIOFunction b <- otherIOFunction a return b
ېஅͷຐ๏͕͋Δ • Future IO ͷੈքʹҰೖͬͨΒجຊతʹೋͱΕͳ͍ • Future ΛऔΓআ͘ېஅͷຐ๏ Await.result
• Await.result(x: Future[A]): A" • εϨουͷ join Έ͍ͨͳͷ͕ͩɺεϨουΛϑϧ׆༻͢Δ ϓϩάϥϜͰ͍͚ͬͯͳ͍ • IO ΛऔΓআ͘ېஅͷຐ๏ unsafePerformIO • unsafePerformIO :: IO a -> a
ࣅ͍ͯͳ͍ͱ͜Ζɿྫ֎ͷѻ͍ • com.twitter.util.Try[A]" • ྫ֎͕ى͜Δ͔͠Εͳ͍ܭࢉΛϥοϓ͢ΔΫϥε • ͜Ε Scala 2.10 Ͱ
scala.util.Try ͱͯ͠ඪ४ʹ • Future[A] ͷ࣮ମ Promise[A] Ͱɺܭࢉ͕ྃͨ͠Β Try[A] ʹͳ͍ͬͯΔ • Try[A] ͷ࣮ମ Return[A] ͘͠ Throw[A] • Return[A] ݁ՌΛϥοϓɺ Throw[A] ྫ֎Λϥοϓ
·ͱΊ • Scala ͷ Future ͱ Haskell ͷ IO ࣅ͍ͯΔ
• ͦΕʹؾ͍ͮͨޙ͢ΜͳΓͱ Future ΛཧղͰ͖ͨ͠ɺϓϩά ϥϜॻ͚ΔΑ͏ʹͳͬͨ • Haskell Λ͍ͬͯΔਓ͕ Scala ͷ Future Λ৮Γ࢝Ίͨͱ͖ʹ ͍ͬͯΔͱศར • Scala ެࣜͷઆ໌Θ͔Γʹ͍͘ͱࢥ͏… http://docs.scala-lang.org/ja/overviews/core/futures.html • twitter/util ͱ twitter/finagle Λಡ͏
ʢهʣ • ཁʮFuture ҰํੑϞφυͳͷͰɺʢ؆୯ʹʣ Εͳ͍͔Β͍ํʹҙʯͱݴ͍ͬͯΔ͚ͩͰ͢ • ҰํੑͷϞφυ Haskell Ͱ IO
͕Ұ൪Θ͔Γ ͍͢ྫͳͷͰɺͦΕͱͷରൺΛڍ͛·ͨ͠