$30 off During Our Annual Pro Sale. View Details »
Speaker Deck
Features
Speaker Deck
PRO
Sign in
Sign up for free
Search
Search
Scalalr
Search
Kazuhiro Ichikawa
March 17, 2018
Programming
1
2.2k
Scalalr
Scalaの型システムを悪用して好きな文法のDSLをScala上で実現するためのライブラリ
Kazuhiro Ichikawa
March 17, 2018
Tweet
Share
More Decks by Kazuhiro Ichikawa
See All by Kazuhiro Ichikawa
Tuples and Mirrors in Scala3 and Higher-Kinded Data
phenan
0
1.5k
自己関手の圏における モノイド対象 in Scala
phenan
0
430
ValiantParsing
phenan
1
84
Intro to typeclass in Scala
phenan
10
2.3k
Other Decks in Programming
See All in Programming
Leveling Up Developer Tooling for the Modern Rails & Hotwire Era @ Ruby Türkiye, November 2024
marcoroth
0
150
DevTools extensions で 独自の DevTool を開発する | FlutterKaigi 2024
kokiyoshida
0
220
Figma Dev Modeで変わる!Flutterの開発体験
watanave
0
3.7k
WebAssembly Unleashed: Powering Server-Side Applications
chrisft25
0
1.9k
Thoughts and experiences on Rust and TypeScript
unvalley
2
190
CSC509 Lecture 13
javiergs
PRO
0
120
大規模サイトリビルドの現場から:成功と失敗のリアルな教訓 / Site Rebuild,Real Lessons Learned from Successes and Failures_JJUG Fall 2024
techtekt
0
180
Jakarta EE meets AI
ivargrimstad
0
1.2k
Full stack testing :: basic to basic
up1
1
720
flutterkaigi_2024.pdf
kyoheig3
0
330
「今のプロジェクトいろいろ大変なんですよ、app/services とかもあって……」/After Kaigi on Rails 2024 LT Night
junk0612
5
2.2k
.NET Conf 2024の振り返り
tomokusaba
0
170
Featured
See All Featured
Building Adaptive Systems
keathley
38
2.3k
Reflections from 52 weeks, 52 projects
jeffersonlam
346
20k
Gamification - CAS2011
davidbonilla
80
5k
RailsConf & Balkan Ruby 2019: The Past, Present, and Future of Rails at GitHub
eileencodes
131
33k
RailsConf 2023
tenderlove
29
910
Build your cross-platform service in a week with App Engine
jlugia
229
18k
Fight the Zombie Pattern Library - RWD Summit 2016
marcelosomers
232
17k
Mobile First: as difficult as doing things right
swwweet
222
8.9k
Being A Developer After 40
akosma
87
590k
It's Worth the Effort
3n
183
27k
What's new in Ruby 2.0
geeforr
343
31k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
26
1.4k
Transcript
4DBMBMS 4DBMBͷݴޠػߏΛѱ༻ͯ͠ ࠷ڧͷ%4-Λ࡞ΔϥΠϒϥϦ !QIFOBO 4DBMB.BUTVSJൃදࢿྉ
• Twitter: @phenan • Github: phenan • ࠓͷ: ໘ന͍ϥΠϒϥϦΛ࡞ͬͨͷͰհ͠·͢ •
͜ͷεϥΠυ: https://speakerdeck.com/phenan/scalalr
͜Μͳײ͡Ͱ%4-Λఆٛ͢Δ
JValue のDSL
JValue のDSL こうかいて これをよびたい
JValue のDSL こうかいて これをよびたい カンマくぎり
JValue のDSL JSONのObjectの かきかた Objectのそれぞれの プロパティ
͜Μͳײ͡Ͱ͑Δʂ
͜Μͳײ͡Ͱ͑Δʂ これ
͜Μͳײ͡Ͱ͑Δʂ これ
͜Μͳײ͡Ͱ͑Δʂ これ これ
ׅހ͕͍ͬͺ͍͋Δ
ׅހݴޠͷڥքΛ͋ΒΘ͢ JSON DSLに Scala value をわたしている
ׅހݴޠͷڥքΛද͢ Scalaに JSON DSLを わたしている 1ライナーのDSLなら()はいらない
ͯ͠΄͍͠
4DBMBͰ͜Μͳͷॻ͚͚ͨͬʁ
4DBMBͰ͜Μͳͷॻ͚͚ͨͬʁ [a, b] ?
4DBMBͰ͜Μͳͷॻ͚͚ͨͬʁ [a, b] ? : のあとは タイプでは?
4DBMBͰ͜Μͳͷॻ͚͚ͨͬʁ [a, b] ? : のあとは タイプでは? {a, b} ?
ίϯύΠϥ֦ுʁ
͍͍͑ɺ ૉͷ4DBMBͰ͢
'POU-JHBUVSF ͜Ε࣮…
'POU-JHBUVSF
'POU-JHBUVSF 7BMJEͳ4DBMBίʔυ
4DBMBMS w ઐ༻ϑΥϯτ4DBMJHͷར༻Λલఏͱͨ͠ίʔυΛੜ͢Δ w %4-ͷݟͨΛࣗ༝ʹม͑ΒΕΔΑʂͬͨͶʂ w ίϯύΠϧʹ͕͔͔࣌ؒΔͷ͕ͪΐͬͱͨ͠ ཁૉͷ+40/ͷྻͷίϯύΠϧʹ࣌ؒҎ্͔͔ͬͨ w ຯʹଧͭͷ͕໘ͳͷͰΤσΟλαϙʔτ։ൃ͍ͨ͠
w IUUQTHJUIVCDPNQIFOBOTDBMBMS
ٕज़తৄࡉ w !ETMΞϊςʔγϣϯϚΫϩ w JNQMJDJUQBSBNFUFSΛѱ༻ͯ͠ίϯύΠϧ࣌-"-3ߏจղੳ w ܕˠඇऴه߸ จ๏Λදݱ͢Δͭ w
ҙͷ෦ࣜΛׅހͰׅͬͨ4DBMBࣜͰஔ͖͑Մೳʹ͢ΔͨΊʹ ͪΐͬͱෳࡶͳ͜ͱΛ͍ͯ͠Δ w ͜ͷख๏ΛԠ༻ͯ͠ࣈ۟ղੳΛมߋՄೳʹ͢Δ͜ͱͰ͖Δ ͣ w ΞϯΧϯϑΝϨϯεͰͯ͠Έ͍ͨ ͚ͲεϥΠυ༻ҙͯ͠ͳ͍
%4-ͷ࡞Γํ w ߏจղੳثΛ࡞ΔϓϩάϥϜ"45 w ΠϯλϓϦλΛ࡞Δ"45
%4-ͷ࡞Γํ w ߏจղੳثΛ࡞ΔϓϩάϥϜ"45 w ΠϯλϓϦλΛ࡞Δ"45 ؔΛݺྑ͍͚ͩ
%4-ͷ࡞Γํ w ߏจղੳثΛ࡞ΔϓϩάϥϜ"45 w ΠϯλϓϦλΛ࡞Δ"45 ؔΛݺྑ͍͚ͩ ͬͪ͜ΛͲ͏͢Δ͔
Λ؆୯ʹ͢Δ w %4-ΛBCDEFʜͷΑ͏ʹॻ͘ͷͱ͢Δ w ϝιουݺͼग़͠PSϑΟʔϧυࢀরͷνΣΠϯ w ࣮͜ͷه๏4DBMBMSαϙʔτ͍ͯ͠Δ
Կ͕Ͱ͖Εྑ͍͔ w ϓϩάϥϜBCDEFʜͷͦΕͧΕͷؔݺͼग़͠Λݕࠪ w ϓϩάϥϜஅยBCͷ͕࣍DͰ͋Δͷਖ਼͍͠ೖྗ͔ʁ w ΦʔτϚτϯΛ࡞Δʂ S1 S2 S3
S4 B C D
Ϋϥεͱϝιου w ঢ়ଶ4ͷͱ͖͚ͩݺΔؔDΛ࡞Εྑ͍ w Ϋϥε4ͷϝιουD͕4ܕͷΛฦͤྑ͍ S1 S2 S3 S4 B
C D
͜Εͩͱਖ਼نදݱ͘Β͍͔͠Ͱ͖ͳ͍ w ܾఆੑ༗ݶΦʔτϚτϯ w ͏গ͠ڧ͍ߏจղੳ͕͍ͨ͠ w -3ߏจղੳΛ࠶ݱ͢Δʂ S1 S2 S3
S4 B C D
-3ΦʔτϚτϯ w ܾఆੑ༗ݶΦʔτϚτϯͷࣗવͳ֦ு w SFEVDF࠷ۙಡΜ͍͔ͩͭ͘ͷτʔΫϯΛͳ͔ͬͨ͜ͱʹͯ͠ɺ ผͷτʔΫϯΛಡΜͩ͜ͱʹ͢Δ S1 S2 S3 S4
&YQS 5FSN S5 /VN /VN S6 5FSN
-3ΦʔτϚτϯ w ܾఆੑ༗ݶΦʔτϚτϯͷࣗવͳ֦ு w SFEVDF࠷ۙಡΜ͍͔ͩͭ͘ͷτʔΫϯΛͳ͔ͬͨ͜ͱʹͯ͠ɺ ผͷτʔΫϯΛಡΜͩ͜ͱʹ͢Δ SFEVDF5FSN/VN SFEVDF&YQS&YQS 5FSN S1
S2 S3 S4 &YQS 5FSN S5 /VN /VN S6 5FSN
*NQMJDJUQBSBNFUFSΛ͏ʂ w 3FEVDFՄೳ͔Ͳ͏͔ΛJNQMJDJUQBSBNFUFSʹ͢Δ w 44Λܦ༝ͯ͠4ʹSFEVDFՄೳͳͷͰ ϝιου͕ݺΔΑ͏ʹ͢Δ SFEVDF5FSN/VN SFEVDF&YQS&YQS 5FSN S1
S2 S3 S4 &YQS 5FSN S5 /VN /VN S6 5FSN
࣮Πϝʔδ implicit class PlusTransition[Sn] (sn: Sn) { def plus (implicit
reduce: SnからS2にreduce可能): S3 = { reduce(sn).plus() } } ҙͷঢ়ଶ4O 4ʹSFEVDFՄೳͰ͋Ε QMVTΛݺͿ͜ͱ͕Ͱ͖Δ
3FEVDFͷఆٛ trait Reduce[Sx, Sy] { def apply (sx: Sx): Sy
} implicit def doubleReduce [Sx, Sy, Sz] (implicit reduce1: Reduce[Sx, Sy], reduce2: Reduce[Sy, Sz]) : Reduce[Sx, Sz] = { new Reduce[Sx, Sz] { def apply (sx: Sx): Sz = reduce2(reduce1(sx)) } } SFEVDFՄೳ͔Ͳ͏͔Λදݱ͢Δ NVMUJQBSBN ܕΫϥε SFEVDFਪҠత 4Y4Z͔ͭ4Z4[ͳΒ4Y4[
3FEVDFͷఆٛ implicit val reduceFromS5ToS6: Reduce[S5, S6] = { new Reduce[S5,
S6] { def apply (s5: S5): S6 = S6(Term(s5.value)) } } 44ͷSFEVDFఆٛ /VNͷΘΓʹ5FSNΛಡΜͩ͜ͱʹ͢Δ SFEVDF5FSN/VN SFEVDF&YQS&YQS 5FSN S1 S2 S3 S4 &YQS 5FSN S5 /VN /VN S6 5FSN
ຊͷ࣮͏গ͠ෳࡶ w -"-3ߏจղੳʹ͢ΔͨΊʹɺ 3FEVDFՄೳ͔Ͳ͏͔ͷஅʹ࣍ͷτʔΫϯΛ͏ w BCDEFʜͰ͕ඞཁͳͷͰɺ ຊBC D E F
ʜͷܗʹ͍ͨ͠ w ͜͏͢ΕBCDEFʜͷΑ͏ʹॻ͚Δʂ w CϝιουΛDΛҾʹͱΔϝιουʹͯ͠ɺ ͭͿΜͷঢ়ଶભҠΛҰؾʹΕྑ͍
ຊͷ࣮ߋʹෳࡶ w ҙͷ෦ࣜΛ 4DBMBͷࣜ Ͱஔ͖͑ΒΕΔΑ͏ʹ͍ͨ͠ w BC D E F
ʜͷͲͷ෦Λஔ͖͑Δ͔ʹΑ͕ͬͯҧ͏ w Bͷ෦JNQMJDJUDMBTTΛఆٛͯ͠CϝιουΛݺΔΑ͏ʹ w Dͷ෦Cϝιου͕4DBMBͷࣜΛҾʹऔΕΔΑ͏ʹ͢Δ w Cͷ෦ʹ4DBMB͕ࣜೖΔͱB C D E F ͱͳΓ݁߹͕มΘΔʂ w B C D Ͱͭͷঢ়ଶભҠΛҰʹΕྑ͍ʂ w ಉ༷ʹOݸͷঢ়ଶભҠΛҰʹΔΈ͕ඞཁ
4DBMBMS<IUUQTHJUIVCDPNQIFOBOTDBMBMS> w ࣮ଶ-"-3 ύʔβδΣωϨʔλ w ී௨ͷύʔβͰͳ͘JNQMJDJUWBMVFͷఆٛΛੜ͢Δ w !ETMΞϊςʔγϣϯϚΫϩʹΑΓίϯύΠϧ࣌ʹίʔυੜ w
ϚΫϩύϥμΠεϚΫϩࠈͩͥ w %4-ϢʔβJNQPSU͢Δ͚ͩͰ%4-Λ͑Δʂ w ίϯύΠϧʹ͕͔͔࣌ؒΔ w -"-3ઢܗͷΞϧΰϦζϜ͕ͩɺ࣮ଌͩͱ0 O ͘Β͍ʹݟ͑Δ