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
20251127 BigQueryリモート関数で作る、お手軽AIバッチ実行環境
daimatz
0
490
Ad Serving System
daimatz
0
1.1k
Dependency Injection からモックライブラリまで
daimatz
4
2.1k
TaPL 読書会 20. Recursive Types
daimatz
3
220
TaPL 読書会 15. Subtyping
daimatz
0
270
Other Decks in Technology
See All in Technology
Authlete で実装する MCP OAuth 認可サーバー #CIMD の実装を添えて
watahani
0
370
研究開発部メンバーの働き⽅ / Sansan R&D Profile
sansan33
PRO
4
21k
20251225_たのしい出張報告&IgniteRecap!
ponponmikankan
0
110
Introduction to Bill One Development Engineer
sansan33
PRO
0
340
Bill One 開発エンジニア 紹介資料
sansan33
PRO
4
17k
[PR] はじめてのデジタルアイデンティティという本を書きました
ritou
0
740
2025年の医用画像AI/AI×medical_imaging_in_2025_generated_by_AI
tdys13
0
290
BidiAgent と Nova 2 Sonic から考える音声 AI について
yama3133
2
140
善意の活動は、なぜ続かなくなるのか ーふりかえりが"構造を変える判断"になった半年間ー
matsukurou
0
170
RALGO : AIを組織に組み込む方法 -アルゴリズム中心組織設計- #RSGT2026 / RALGO: How to Integrate AI into an Organization – Algorithm-Centric Organizational Design
kyonmm
PRO
3
440
SES向け、生成AI時代におけるエンジニアリングとセキュリティ
longbowxxx
0
290
ルネサンス開発者を育てる 1on1支援AIエージェント
yusukeshimizu
0
130
Featured
See All Featured
GraphQLの誤解/rethinking-graphql
sonatard
74
11k
How to build a perfect <img>
jonoalderson
1
4.8k
Connecting the Dots Between Site Speed, User Experience & Your Business [WebExpo 2025]
tammyeverts
10
770
Skip the Path - Find Your Career Trail
mkilby
0
30
SEOcharity - Dark patterns in SEO and UX: How to avoid them and build a more ethical web
sarafernandez
0
98
How To Speak Unicorn (iThemes Webinar)
marktimemedia
1
360
My Coaching Mixtape
mlcsv
0
20
Organizational Design Perspectives: An Ontology of Organizational Design Elements
kimpetersen
PRO
0
48
Why Mistakes Are the Best Teachers: Turning Failure into a Pathway for Growth
auna
0
32
Are puppies a ranking factor?
jonoalderson
0
2.6k
From Legacy to Launchpad: Building Startup-Ready Communities
dugsong
0
120
The agentic SEO stack - context over prompts
schlessera
0
580
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
͕Ұ൪Θ͔Γ ͍͢ྫͳͷͰɺͦΕͱͷରൺΛڍ͛·ͨ͠