From dac1248c7ef0c548fa94fe4a72409d15e3a8afc8 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Sun, 21 Dec 2014 18:00:36 +0530
Subject: [PATCH] hw5: exercise 4

---
 hw5/Calc.hs | 28 ++++++++++++++++++++++++++++
 1 file changed, 28 insertions(+)

diff --git a/hw5/Calc.hs b/hw5/Calc.hs
index 46f7820..3d8dd9b 100644
--- a/hw5/Calc.hs
+++ b/hw5/Calc.hs
@@ -28,3 +28,31 @@ instance Expr ExprT where
   lit = Lit
   add = Add
   mul = Mul
+
+reify :: ExprT -> ExprT
+reify = id
+
+instance Expr Integer where
+  lit = id
+  add = (+)
+  mul = (-)
+
+instance Expr Bool where
+  lit x | x <= 0 = False
+        | otherwise = True
+  add = (||)
+  mul = (&&)
+
+newtype MinMax = MinMax Integer deriving (Show, Eq)
+
+instance Expr MinMax where
+  lit = MinMax
+  add (MinMax x) (MinMax y) = MinMax (max x y)
+  mul (MinMax x) (MinMax y) = MinMax (min x y)
+
+newtype Mod7 = Mod7 Integer deriving (Show, Eq)
+
+instance Expr Mod7 where
+  lit x = Mod7 (x `mod` 7)
+  add (Mod7 x) (Mod7 y) = Mod7 ((x+y) `mod` 7)
+  mul (Mod7 x) (Mod7 y) = Mod7 ((x*y) `mod` 7)
-- 
2.45.2