This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (** This is a demonstration of implementing interpreters in an extensible way | |
| that offers a partial solution to the expression problem. The idea is that | |
| the language can be extended with more features after the fact, without | |
| altering previous definitions. It also has the benefit of grouping the | |
| related extensions to the syntax and semantic domains together with the | |
| relevant evaluation rules in a per-feature way. | |
| This approach used is similar to the one described by Matthias Blume in | |
| {{:https://www.microsoft.com/en-us/research/video/records-sums-cases-and-exceptions-row-polymorphism-at-work/} | |
| Records, sums, cases, and exceptions: Row-polymorphism at work}. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data P = R | L | Seq P P | Loop P | |
| data Tape = Tape [Int] Int [Int] | |
| empty :: Tape | |
| empty = Tape (repeat 0) 0 (repeat 0) | |
| left :: Tape -> Tape | |
| left (Tape (l:ls) v rs) = Tape ls l (v:rs) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| data Bool { T, F } | |
| data Nat { Z, S(n: Nat) } | |
| def (n1: Nat).eq(n2: Nat): Bool { | |
| Z => n2.match { | |
| Z => T, | |
| S(_) => F, | |
| }, | |
| S(n1) => n2.match { |
OlderNewer