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
980
Dependency Injection からモックライブラリまで
daimatz
4
1.9k
TaPL 読書会 20. Recursive Types
daimatz
3
190
TaPL 読書会 15. Subtyping
daimatz
0
200
Other Decks in Technology
See All in Technology
エンジニア向け会社紹介資料
caddi_eng
14
220k
Luupの開発組織におけるインシデントマネジメントの変遷 ver.RoadtoSRENEXT2024
grimoh
1
270
ソフトウェアエンジニアリングの知見を活かして データ基盤をいい感じにする on Snowflake [MIERUNE BBQ #10]
mtpooh
2
150
DDDにおける認可の扱いとKotlinにおける実装パターン / authorization-for-ddd-and-kotlin-implement-pattern
urmot
4
390
累計ダウンロード数1億8000万を超えるアプリケーションプラットフォームのレガシーシステム脱却とモダン化への道
kmitsuhashi
0
120
Scaling Technical Excellence at 104: Evolution in AWS and Developer Empowerment
scotthsieh825
1
150
さらに高品質・高速化を目指すAI時代のテスト設計支援と、めざす先 / AI Test Lab vol.1
shift_evolve
0
190
AIエージェントを現場に導入する目線とは
masahiro_nishimi
1
1.5k
簡単に始めるSnowflakeの機械学習
nayuts
1
190
「我々はどこに向かっているのか」を問い続けるための仕組みづくり / Establishing a System for Continuous Inquiry about where we are
daitasu
0
170
AWSで”最小権限の原則”を実現するための考え方 /20240722-ssmjp-aws-least-privilege
opelab
10
4.3k
開発生産性をむしろ向上させる セキュリティパートナーの作り方 / Dev Productivity Con 2024
flatt_security
0
360
Featured
See All Featured
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
155
14k
The Cult of Friendly URLs
andyhume
75
5.9k
Done Done
chrislema
179
15k
Making the Leap to Tech Lead
cromwellryan
127
8.7k
Building Flexible Design Systems
yeseniaperezcruz
323
37k
Clear Off the Table
cherdarchuk
89
320k
I Don’t Have Time: Getting Over the Fear to Launch Your Podcast
jcasabona
26
1.8k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
129
32k
Product Roadmaps are Hard
iamctodd
PRO
48
10k
How STYLIGHT went responsive
nonsquared
93
5k
Designing Dashboards & Data Visualisations in Web Apps
destraynor
226
52k
Design by the Numbers
sachag
277
18k
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
͕Ұ൪Θ͔Γ ͍͢ྫͳͷͰɺͦΕͱͷରൺΛڍ͛·ͨ͠