Skip to content

Instantly share code, notes, and snippets.

@maciejsmolinski
Created May 20, 2020 23:40
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save maciejsmolinski/189d00ec355017c21f85b2f1ae0ff2d5 to your computer and use it in GitHub Desktop.
Save maciejsmolinski/189d00ec355017c21f85b2f1ae0ff2d5 to your computer and use it in GitHub Desktop.
Simple EDSL in PureScript
module Main where
import Data.Traversable (traverse_)
import Effect (Effect)
import Effect.Console (logShow)
import Prelude
data Expression
= Num Int
| Add Expression Expression
| Subtract Expression Expression
eval :: Expression -> Int
eval (Num a) = a
eval (Add a b) = (eval a) + (eval b)
eval (Subtract a b) = (eval a) - (eval b)
expressions :: Array Expression
expressions =
[ Num 1 -- 1
, Add (Num 1) (Num 2) -- 1 + 2
, Subtract (Add (Num 1) (Num 2)) (Num 2) -- (1 + 2) - 2
]
main :: Effect Unit
main = traverse_ (logShow <<< eval) expressions
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment