Skip to content

Instantly share code, notes, and snippets.

@radustoenescu
Last active August 29, 2015 13:57
Show Gist options
  • Save radustoenescu/9653203 to your computer and use it in GitHub Desktop.
Save radustoenescu/9653203 to your computer and use it in GitHub Desktop.
Types Lab 2
{- 1. write an ADT which encodes arithmetic expressions containing +, * or parentheses -}
data Expr a =
{-- 2. display an expression nicely --}
instance Show a => Show (Expr a) where
{- 3. write a function which evaluates an expression. Also, write it's type -}
{- 4. Write a function which eliminates parentheses from an expression.
e * (3) = e * 3
(3) * e = e * (3)
e * (e' + e'') = e * e' + e * e''
(e' + e'') * e = e * (e' + e'')
e * (e' * e'') = e * e' * e''
(e' * e'') * e = e * (e' * e'')
e + (e') = e + e'
(e') + e = e + (e')
-}
{- 5. Define a mini-programming language working with Numerics.
The programming language has the following construct:
x = e (assignment)
if e then e' else e'' (conditional. Can only be an expression 0 evaluates to false, everything else evaluates to true)
e ; e' (sequence)
return x (x can only be a variable)
-}
{- 6. display a program nicely -}
{- 7. define a function whose name must also be eval, which can evaluate a program -}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment