summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--lec05/Calc.hs17
1 files changed, 16 insertions, 1 deletions
diff --git a/lec05/Calc.hs b/lec05/Calc.hs
index cd6f408..f97d784 100644
--- a/lec05/Calc.hs
+++ b/lec05/Calc.hs
@@ -15,4 +15,19 @@ eval (Mul l r) = eval l * eval r
evalStr :: String -> Maybe Integer
evalStr s = case parseExp Lit Add Mul s of
Nothing -> Nothing
- Just t -> Just (eval t)
+ Just t -> Just (eval t)
+
+-- Exercise 3
+
+class Expr a where
+ lit :: Integer -> a
+ add :: a -> a -> a
+ mul :: a -> a -> a
+
+instance Expr ExprT where
+ lit = Lit
+ add = Add
+ mul = Mul
+
+reify :: ExprT -> ExprT
+reify = id