X-Git-Url: https://git.rkrishnan.org/?a=blobdiff_plain;f=hw5%2FCalc.hs;h=46f782018c617ae69a0bb440c77af5a753d1cbed;hb=04036d0605e95c06f5d6dea11c2618267c059550;hp=ef4fd2e2542a1d2ccf8cbb22ed01e335d2f42b74;hpb=305e0c26a007817bb0194358bdb52ad5092e6371;p=yorgey.git diff --git a/hw5/Calc.hs b/hw5/Calc.hs index ef4fd2e..46f7820 100644 --- a/hw5/Calc.hs +++ b/hw5/Calc.hs @@ -18,3 +18,13 @@ evalStr :: String -> Maybe Integer -- Just e -> Just (eval e) -- Nothing -> Nothing evalStr s = fmap eval (parseExp Lit Add Mul s) + +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