From 305e0c26a007817bb0194358bdb52ad5092e6371 Mon Sep 17 00:00:00 2001
From: Ramakrishnan Muthukrishnan <ram@rkrishnan.org>
Date: Sun, 21 Dec 2014 16:21:28 +0530
Subject: [PATCH] hw5: exercise 1 and 2

---
 hw5/Calc.hs | 20 ++++++++++++++++++++
 1 file changed, 20 insertions(+)
 create mode 100644 hw5/Calc.hs

diff --git a/hw5/Calc.hs b/hw5/Calc.hs
new file mode 100644
index 0000000..ef4fd2e
--- /dev/null
+++ b/hw5/Calc.hs
@@ -0,0 +1,20 @@
+{-# OPTIONS_GHC -Wall #-}
+
+module Calc where
+
+import ExprT
+import Parser
+
+eval :: ExprT -> Integer
+
+-- exercise 1
+eval (Lit n) = n
+eval (Add e1 e2) = eval e1 + eval e2
+eval (Mul e1 e2) = eval e1 * eval e2
+
+-- exercise 2
+evalStr :: String -> Maybe Integer
+-- evalStr s = case (parseExp Lit Add Mul s) of
+--               Just e -> Just (eval e)
+--              Nothing -> Nothing
+evalStr s = fmap eval (parseExp Lit Add Mul s)
-- 
2.45.2