summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEdoardo La Greca2025-07-10 00:37:43 +0200
committerEdoardo La Greca2025-07-10 00:37:43 +0200
commit2b6de7cb0402e67dd8792d45a9466d7b085666af (patch)
treee3535543c432ef119a82fe405ec4bdd017e7c9cc
parent319643faf6baea1c44f68800cba1947799935d05 (diff)
add third exercise of lecture 5
-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