From 2b6de7cb0402e67dd8792d45a9466d7b085666af Mon Sep 17 00:00:00 2001 From: Edoardo La Greca Date: Thu, 10 Jul 2025 00:37:43 +0200 Subject: add third exercise of lecture 5 --- lec05/Calc.hs | 17 ++++++++++++++++- 1 file changed, 16 insertions(+), 1 deletion(-) (limited to 'lec05/Calc.hs') 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 -- cgit v1.2.3