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
Flutterによる 効率的なAndroid・iOS・Webアプリケーション開発の事例
recruitengineers
PRO
0
150
複雑なState管理からの脱却
sansantech
PRO
1
170
開発生産性を上げながらビジネスも30倍成長させてきたチームの姿
kamina_zzz
2
1.7k
OCI 運用監視サービス 概要
oracle4engineer
PRO
0
4.8k
日経電子版のStoreKit2フルリニューアル
shimastripe
1
160
【令和最新版】AWS Direct Connectと愉快なGWたちのおさらい
minorun365
PRO
5
800
10XにおけるData Contractの導入について: Data Contract事例共有会
10xinc
7
720
100 名超が参加した日経グループ横断の競技型 AWS 学習イベント「Nikkei Group AWS GameDay」の紹介/mediajaws202411
nikkei_engineer_recruiting
1
180
電話を切らさない技術 電話自動応答サービスを支える フロントエンド
barometrica
2
320
EventHub Startup CTO of the year 2024 ピッチ資料
eventhub
0
130
『Firebase Dynamic Links終了に備える』 FlutterアプリでのAdjust導入とDeeplink最適化
techiro
0
220
Making your applications cross-environment - OSCG 2024 NA
salaboy
0
210
Featured
See All Featured
Easily Structure & Communicate Ideas using Wireframe
afnizarnur
191
16k
How to train your dragon (web standard)
notwaldorf
88
5.7k
A Philosophy of Restraint
colly
203
16k
GraphQLとの向き合い方2022年版
quramy
43
13k
Documentation Writing (for coders)
carmenintech
65
4.4k
The World Runs on Bad Software
bkeepers
PRO
65
11k
Fantastic passwords and where to find them - at NoRuKo
philnash
50
2.9k
Designing the Hi-DPI Web
ddemaree
280
34k
CoffeeScript is Beautiful & I Never Want to Write Plain JavaScript Again
sstephenson
159
15k
Building Better People: How to give real-time feedback that sticks.
wjessup
364
19k
Happy Clients
brianwarren
98
6.7k
No one is an island. Learnings from fostering a developers community.
thoeni
19
3k
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
͕Ұ൪Θ͔Γ ͍͢ྫͳͷͰɺͦΕͱͷରൺΛڍ͛·ͨ͠