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
1.9k
Scala の Future と Haskell の IO
daimatz
May 11, 2014
Tweet
Share
More Decks by daimatz
See All by daimatz
Ad Serving System
daimatz
0
1k
Dependency Injection からモックライブラリまで
daimatz
4
2k
TaPL 読書会 20. Recursive Types
daimatz
3
190
TaPL 読書会 15. Subtyping
daimatz
0
220
Other Decks in Technology
See All in Technology
DynamoDB でスロットリングが発生したとき/when_throttling_occurs_in_dynamodb_short
emiki
0
260
インフラとバックエンドとフロントエンドをくまなく調べて遅いアプリを早くした件
tubone24
1
430
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
760
Lexical Analysis
shigashiyama
1
150
プロダクト活用度で見えた真実 ホリゾンタルSaaSでの顧客解像度の高め方
tadaken3
0
200
適材適所の技術選定 〜GraphQL・REST API・tRPC〜 / Optimal Technology Selection
kakehashi
1
700
OCI Security サービス 概要
oracle4engineer
PRO
0
6.5k
The Rise of LLMOps
asei
9
1.7k
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
6
680
Engineer Career Talk
lycorp_recruit_jp
0
190
エンジニア人生の拡張性を高める 「探索型キャリア設計」の提案
tenshoku_draft
1
130
Application Development WG Intro at AppDeveloperCon
salaboy
0
200
Featured
See All Featured
Visualizing Your Data: Incorporating Mongo into Loggly Infrastructure
mongodb
42
9.2k
Refactoring Trust on Your Teams (GOTO; Chicago 2020)
rmw
31
2.7k
What’s in a name? Adding method to the madness
productmarketing
PRO
22
3.1k
Thoughts on Productivity
jonyablonski
67
4.3k
CSS Pre-Processors: Stylus, Less & Sass
bermonpainter
356
29k
Why You Should Never Use an ORM
jnunemaker
PRO
54
9.1k
Done Done
chrislema
181
16k
JavaScript: Past, Present, and Future - NDC Porto 2020
reverentgeek
47
5k
How STYLIGHT went responsive
nonsquared
95
5.2k
Six Lessons from altMBA
skipperchong
27
3.5k
Documentation Writing (for coders)
carmenintech
65
4.4k
GitHub's CSS Performance
jonrohan
1030
460k
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
͕Ұ൪Θ͔Γ ͍͢ྫͳͷͰɺͦΕͱͷରൺΛڍ͛·ͨ͠