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
自作プログラミング言語Malgoの紹介
Search
Yuya Kono
June 13, 2021
Programming
0
190
自作プログラミング言語Malgoの紹介
『プログラミング言語処理系が好きな人の集まり』での定期ミートアップ(2021/06/13)で発表した資料です
Yuya Kono
June 13, 2021
Tweet
Share
More Decks by Yuya Kono
See All by Yuya Kono
プログラミングの暗黙知
takoeight0821
0
84
git logで振り返る大学4年間
takoeight0821
1
180
自作言語にモジュールを実装した話
takoeight0821
0
400
量子コンピュータで乱数を生成した話
takoeight0821
1
270
自作言語コンパイラを作った話
takoeight0821
0
170
自作言語malgoのコンパイラをリファクタリングした話
takoeight0821
0
340
今日から始める自作コンパイラ ver 0.0.1
takoeight0821
0
1.1k
Language Server Protocolの話
takoeight0821
0
430
GraalVMで遊ぶ
takoeight0821
0
170
Other Decks in Programming
See All in Programming
Writing Better Go: Lessons from 10 Code Reviews
konradreiche
3
5.3k
Devoxx BE - Local Development in the AI Era
kdubois
0
130
Flutterで分数(Fraction)を表示する方法
koukimiura
0
140
他言語経験者が Golangci-lint を最初のコーディングメンターにした話 / How Golangci-lint Became My First Coding Mentor: A Story from a Polyglot Programmer
uma31
0
330
contribution to astral-sh/uv
shunsock
0
440
あなたとKaigi on Rails / Kaigi on Rails + You
shimoju
0
170
Things You Thought You Didn’t Need To Care About That Have a Big Impact On Your Job
hollycummins
0
250
Le côté obscur des IA génératives
pascallemerrer
0
150
3年ぶりにコードを書いた元CTOが Claude Codeと30分でMVPを作った話
maikokojima
0
610
オープンソースソフトウェアへの解像度🔬
utam0k
17
3.1k
技術的負債の正体を知って向き合う
irof
0
210
Six and a half ridiculous things to do with Quarkus
hollycummins
0
210
Featured
See All Featured
YesSQL, Process and Tooling at Scale
rocio
173
14k
The Cost Of JavaScript in 2023
addyosmani
55
9.1k
Distributed Sagas: A Protocol for Coordinating Microservices
caitiem20
333
22k
XXLCSS - How to scale CSS and keep your sanity
sugarenia
249
1.3M
A better future with KSS
kneath
239
18k
10 Git Anti Patterns You Should be Aware of
lemiorhan
PRO
657
61k
The World Runs on Bad Software
bkeepers
PRO
72
11k
How to Create Impact in a Changing Tech Landscape [PerfNow 2023]
tammyeverts
55
3k
Git: the NoSQL Database
bkeepers
PRO
431
66k
Understanding Cognitive Biases in Performance Measurement
bluesmoon
31
2.7k
Optimising Largest Contentful Paint
csswizardry
37
3.5k
Sharpening the Axe: The Primacy of Toolmaking
bcantrill
46
2.5k
Transcript
ʹΌʔΜʢ!UBLPFJHIUʣ ࣗ࡞ϓϩάϥϛϯάݴޠ .BMHPͷհ
ʹΌΜͰ͢ !UBLPFJHIU
ࣗ࡞ݴޠ.BMHP IUUQTHJUIVCDPNNBMHPMBOHNBMHP w ੩తܕ͖ؔϓϩάϥϛϯάݴޠ w ܕਪɺతσʔλܕɺύλʔϯϚον w )BTLFMMͬΆ͍ߏจ w ܕએݴUZQF
EBUB w ΠϯσϯτϕʔεͰͳ͍ w ؔϦςϥϧͷߏจͳͲɺҧ͏ͱ͜Ζଟ͍
ࣗ࡞ݴޠ.BMHP IUUQTHJUIVCDPNNBMHPMBOHNBMHP w ੩తܕ͖ؔϓϩάϥϛϯάݴޠ w ܕਪɺతσʔλܕɺύλʔϯϚον w )BTLFMMͬΆ͍ߏจ w ܕએݴUZQF
EBUB w ΠϯσϯτϕʔεͰͳ͍ w ؔϦςϥϧͷߏจͳͲɺҧ͏ͱ͜Ζଟ͍ ࠓύλʔϯϚονͷίϯύΠϧʹ͍ͭͯ͠·͢
.BMHPͰॻ͍ͨϓϩάϥϜ data Bool = False | True; if :: Bool
-> {a} -> {a} -> a; if c t f = c |> { True -> !t | False -> !f }; ifΛؔͱͯ͠ϢʔβʔఆٛͰ͖Δʂ
.BMHPͰॻ͍ͨϓϩάϥϜ ύλʔϯϚονͱ༥߹ͨؔ͠Ϧςϥϧ Int#ͷϥούʔΦϒδΣΫτͷΑ͏ͳͷ data List a = Nil | Cons
a (List a); sum = { Nil -> Int# 0L# | (Cons (Int# x) xs) -> sum xs |> {(Int# s) -> Int# (x +# s)} }
ύλʔϯϚονͷίϯύΠϧ
ύλʔϯϚονͷίϯύΠϧ w .BMHPڧྗͳʢؔܕݴޠʹΑ͋͘ΔʣύλʔϯϚονΛͭ w ҙͷϢʔβʔఆٛܕʹରͯ͠ɺೖΕࢠΛͭύλʔϯΛهड़Ͱ͖Δ w ύλʔϯϚονΛTXJUDIDBTFʹམͱ͠ࠐΉඞཁ͕͋Δ w ҙຯతʹ্͔ΒԼʹ࣮ߦ͢ΔJGͰ͍͍͕ɺظ͞ΕΔڍಈTXJUDIDBTF w
ύλʔϯϚονͷίϯύΠϧख๏ʹ͍ͭͯ͋·Γࢿྉ͕ͳ͍ w 5IF*NQMFNFOUBUJPOPG'VODUJPOBM1SPHSBNNJOH-BOHVBHFTʹ ؆୯ͳ࣮ํ๏ͷهड़͕͋ͬͨ
͜ͷϓϩάϥϜʹ͍ͭͯߟ͑Δ { Nil -> Int# 0L# | (Cons (Int# x)
xs) -> sum xs |> {(Int# s) -> Int# (x +# s)} } match [u1] [ ( [Nil], Int# 0L# ), ( [Cons (Int# x) xs], sum xs ...) ] ERROR ԼͷΑ͏ͳதؒදݱΛߟ͑ɺίϯύΠϧ͢Δ
ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (
[Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢ΔؔmatchΛߟ͑Δ ୈҰҾύλʔϯϚονͷରʹͳΔมʢTDSVUJOFFʣͷྻ ୈೋҾύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷͷྻ ୈࡾҾͲͷύλʔϯʹ߹க͠ͳ͔ͬͨͱ͖ͷࣜ
ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (
[Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢ΔؔmatchΛߟ͑Δ ୈҰҾύλʔϯϚονͷରʹͳΔมʢTDSVUJOFFʣͷྻ ୈೋҾύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷͷྻ ୈࡾҾͲͷύλʔϯʹ߹க͠ͳ͔ͬͨͱ͖ͷࣜ
ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (
[Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢ΔؔmatchΛߟ͑Δ ୈҰҾύλʔϯϚονͷରʹͳΔมʢTDSVUJOFFʣͷྻ ୈೋҾύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷͷྻ ୈࡾҾͲͷύλʔϯʹ߹க͠ͳ͔ͬͨͱ͖ͷࣜ
ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (
[Cons (Int# x) xs], sum xs ...) ] ERROR ୈೋҾͷύλʔϯͷઌ಄ʹ͢ΔʢࠓճͦͦҰݸ͔͠ͳ͍ʣ Nil͜ΕҎ্ฏୱʹͳΒͳ͍ͷͰ͜ͷ·· Cons (Int# x) xs(Int# x)Λల։͠ͳ͍ͱ͍͚ͳ͍
ύλʔϯϚονͷίϯύΠϧNBUDI match u1 with | Nil -> Int# 0L# |
Cons u2 u3 -> match [u2, u3] [ ( [Int# x, xs], sum xs ...) ] ERROR Ұ࣌มu2 u3Λ༻͍ͯɺu1ʹରԠ͢ΔύλʔϯΛల։ NilͷઅίϯύΠϧऴྃ ConsͷҾInt# x, xs͕࣍ͷmatchʹ͞ΕΔ ࣍Int# xΛల։͢Δ
ύλʔϯϚονͷίϯύΠϧNBUDI match u1 with | Nil -> Int# 0L# |
Cons u2 u3 -> match u2 with | Int# u4 -> match [u4, u3] [ ( [x, xs], sum xs ...) ] ERROR xΛ͍ͬͯΔͯ͢ͷύλʔϯͷઌ಄ʹՃ ʢ͜͜ͰҰ͔ͭ͠ͳ͍͕ʜʣ
ύλʔϯϚονͷίϯύΠϧNBUDI match u1 with | Nil -> Int# 0L# |
Cons u2 u3 -> match u2 with | Int# u4 -> sum u3 |> {(Int# s) -> Int# (u4 +# s)} มύλʔϯͷల։ࣗ໌ʢஔ͖͑Δ͚ͩʣ ͯ͢ͷύλʔϯ͔ΒೖΕࢠ͕ͳ͘ͳͬͨ ͜͏͍͏NBUDIXJUITXJUDIDBTF؆୯ʹίϯύΠϧͰ͖Δ
ࠓޙͷωλ
ࠓޙͷωλ w ܕਪͷΞϧΰϦζϜͱ࣮ w తσʔλܕͷ࣮ߦ࣌දݱ w ΫϩʔδϟͷίϯύΠϧ w ଟ૬ؔͷ࣮ํࣜͱϘοΫεԽ w
ׂίϯύΠϧͷ࣮ݱํ๏ w தؒදݱ,PSJFMͷઃܭ .BMHP·ͩ·ͩ։ൃ్த Լͷͱ͜ΖܕݕࠪثͷόάΛमਖ਼ IUUQTHJUIVCDPNNBMHPMBOHNBMHP