Upgrade to Pro — share decks privately, control downloads, hide ads and more …

自作プログラミング言語Malgoの紹介

 自作プログラミング言語Malgoの紹介

『プログラミング言語処理系が好きな人の集まり』での定期ミートアップ(2021/06/13)で発表した資料です

Yuya Kono

June 13, 2021
Tweet

More Decks by Yuya Kono

Other Decks in Programming

Transcript

  1. ࣗ࡞ݴޠ.BMHP IUUQTHJUIVCDPNNBMHPMBOHNBMHP w ੩తܕ෇͖ؔ਺ϓϩάϥϛϯάݴޠ w ܕਪ࿦ɺ୅਺తσʔλܕɺύλʔϯϚον w ΍΍)BTLFMMͬΆ͍ߏจ w ܕએݴ͸UZQF

    EBUB w ΠϯσϯτϕʔεͰ͸ͳ͍ w ؔ਺ϦςϥϧͷߏจͳͲɺҧ͏ͱ͜Ζ΋ଟ͍ ࠓ೔͸ύλʔϯϚονͷίϯύΠϧʹ͍ͭͯ࿩͠·͢
  2. .BMHPͰॻ͍ͨϓϩάϥϜ data Bool = False | True; if :: Bool

    -> {a} -> {a} -> a; if c t f = c |> { True -> !t | False -> !f }; ifΛؔ਺ͱͯ͠ϢʔβʔఆٛͰ͖Δʂ
  3. .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)} }
  4. ͜ͷϓϩάϥϜʹ͍ͭͯߟ͑Δ { 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 ԼͷΑ͏ͳதؒදݱΛߟ͑ɺίϯύΠϧ͢Δ
  5. ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (

    [Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢Δؔ਺matchΛߟ͑Δ ୈҰҾ਺͸ύλʔϯϚονͷର৅ʹͳΔม਺ʢTDSVUJOFFʣͷྻ ୈೋҾ਺͸ύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷ૊ͷྻ ୈࡾҾ਺͸Ͳͷύλʔϯʹ΋߹க͠ͳ͔ͬͨͱ͖ͷࣜ
  6. ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (

    [Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢Δؔ਺matchΛߟ͑Δ ୈҰҾ਺͸ύλʔϯϚονͷର৅ʹͳΔม਺ʢTDSVUJOFFʣͷྻ ୈೋҾ਺͸ύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷ૊ͷྻ ୈࡾҾ਺͸Ͳͷύλʔϯʹ΋߹க͠ͳ͔ͬͨͱ͖ͷࣜ
  7. ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (

    [Cons (Int# x) xs], sum xs ...) ] ERROR ύλʔϯϚονΛల։͢Δؔ਺matchΛߟ͑Δ ୈҰҾ਺͸ύλʔϯϚονͷର৅ʹͳΔม਺ʢTDSVUJOFFʣͷྻ ୈೋҾ਺͸ύλʔϯͱͦͷύλʔϯʹ߹க͢Δ࣌ͷࣜͷ૊ͷྻ ୈࡾҾ਺͸Ͳͷύλʔϯʹ΋߹க͠ͳ͔ͬͨͱ͖ͷࣜ
  8. ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (

    [Cons (Int# x) xs], sum xs ...) ] ERROR ୈೋҾ਺ͷύλʔϯͷઌ಄ʹ஫໨͢Δʢࠓճ͸ͦ΋ͦ΋Ұݸ͔͠ͳ͍ʣ Nil͸͜ΕҎ্ฏୱʹͳΒͳ͍ͷͰ͜ͷ·· Cons (Int# x) xs͸(Int# x)Λల։͠ͳ͍ͱ͍͚ͳ͍
  9. ύλʔϯϚονͷίϯύΠϧ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Λల։͢Δ
  10. ύλʔϯϚονͷίϯύΠϧNBUDI match u1 with | Nil -> Int# 0L# |

    Cons u2 u3 -> match u2 with | Int# u4 -> match [u4, u3] [ ( [x, xs], sum xs ...) ] ERROR xΛ࢒͍ͬͯΔ͢΂ͯͷύλʔϯͷઌ಄ʹ௥Ճ 
 ʢ͜͜Ͱ͸Ұ͔ͭ͠ͳ͍͕ʜʣ
  11. ύλʔϯϚονͷίϯύΠϧNBUDI match u1 with | Nil -> Int# 0L# |

    Cons u2 u3 -> match u2 with | Int# u4 -> sum u3 |> {(Int# s) -> Int# (u4 +# s)} ม਺ύλʔϯͷల։͸ࣗ໌ʢஔ͖׵͑Δ͚ͩʣ ͢΂ͯͷύλʔϯ͔ΒೖΕࢠ͕ͳ͘ͳͬͨ ͜͏͍͏NBUDIXJUI͸TXJUDIDBTF΁؆୯ʹίϯύΠϧͰ͖Δ
  12. ࠓޙͷωλ w ܕਪ࿦ͷΞϧΰϦζϜͱ࣮૷ w ୅਺తσʔλܕͷ࣮ߦ࣌දݱ w ΫϩʔδϟͷίϯύΠϧ w ଟ૬ؔ਺ͷ࣮૷ํࣜͱϘοΫεԽ w

    ෼ׂίϯύΠϧͷ࣮ݱํ๏ w தؒදݱ,PSJFMͷઃܭ .BMHP͸·ͩ·ͩ։ൃ్த ໨Լͷͱ͜ΖܕݕࠪثͷόάΛमਖ਼ IUUQTHJUIVCDPNNBMHPMBOHNBMHP