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. ੕ʹΌʔΜʢ!UBLPFJHIUʣ ࣗ࡞ϓϩάϥϛϯάݴޠ .BMHPͷ঺հ

  2. ੕ʹΌ—ΜͰ͢ !UBLPFJHIU

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

    EBUB w ΠϯσϯτϕʔεͰ͸ͳ͍ w ؔ਺ϦςϥϧͷߏจͳͲɺҧ͏ͱ͜Ζ΋ଟ͍
  4. ࣗ࡞ݴޠ.BMHP IUUQTHJUIVCDPNNBMHPMBOHNBMHP w ੩తܕ෇͖ؔ਺ϓϩάϥϛϯάݴޠ w ܕਪ࿦ɺ୅਺తσʔλܕɺύλʔϯϚον w ΍΍)BTLFMMͬΆ͍ߏจ w ܕએݴ͸UZQF

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

    -> {a} -> {a} -> a; if c t f = c |> { True -> !t | False -> !f }; ifΛؔ਺ͱͯ͠ϢʔβʔఆٛͰ͖Δʂ
  6. .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)} }
  7. ύλʔϯϚονͷίϯύΠϧ

  8. ύλʔϯϚονͷίϯύΠϧ w .BMHP͸ڧྗͳʢؔ਺ܕݴޠʹΑ͋͘ΔʣύλʔϯϚονΛ΋ͭ w ೚ҙͷϢʔβʔఆٛܕʹରͯ͠ɺೖΕࢠΛ΋ͭύλʔϯΛهड़Ͱ͖Δ w ύλʔϯϚονΛTXJUDIDBTFʹམͱ͠ࠐΉඞཁ͕͋Δ w ҙຯతʹ͸্͔ΒԼʹ࣮ߦ͢ΔJGͰ͍͍͕ɺظ଴͞ΕΔڍಈ͸TXJUDIDBTF w

    ύλʔϯϚονͷίϯύΠϧख๏ʹ͍ͭͯ͸͋·Γࢿྉ͕ͳ͍ w 5IF*NQMFNFOUBUJPOPG'VODUJPOBM1SPHSBNNJOH-BOHVBHFTʹ 
 ؆୯ͳ࣮૷ํ๏ͷهड़͕͋ͬͨ
  9. ͜ͷϓϩάϥϜʹ͍ͭͯߟ͑Δ { 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 ԼͷΑ͏ͳதؒදݱΛߟ͑ɺίϯύΠϧ͢Δ
  10. ύλʔϯϚονͷίϯύΠϧNBUDI match [u1] [ ( [Nil], Int# 0L# ), (

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

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

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

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

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

    Cons u2 u3 -> match u2 with | Int# u4 -> sum u3 |> {(Int# s) -> Int# (u4 +# s)} ม਺ύλʔϯͷల։͸ࣗ໌ʢஔ͖׵͑Δ͚ͩʣ ͢΂ͯͷύλʔϯ͔ΒೖΕࢠ͕ͳ͘ͳͬͨ ͜͏͍͏NBUDIXJUI͸TXJUDIDBTF΁؆୯ʹίϯύΠϧͰ͖Δ
  17. ࠓޙͷωλ

  18. ࠓޙͷωλ w ܕਪ࿦ͷΞϧΰϦζϜͱ࣮૷ w ୅਺తσʔλܕͷ࣮ߦ࣌දݱ w ΫϩʔδϟͷίϯύΠϧ w ଟ૬ؔ਺ͷ࣮૷ํࣜͱϘοΫεԽ w

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