Last active
August 29, 2015 13:57
-
-
Save radustoenescu/9653203 to your computer and use it in GitHub Desktop.
Types Lab 2
This file contains 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
{- 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