-- This is the arith.hs that was handed out in the lecture. data Expr -- introduce a new type, Expr = Literal Int -- an Expr can be (Literal i) where i is an Int | Negated Expr | Sum Expr Expr | Difference Expr Expr | Product Expr Expr | Quotient Expr Expr | Remainder Expr Expr instance Show Expr -- how to print Exprs where showsPrec _ (Literal x) s = shows x s showsPrec _ (Negated e) s = "-" ++ shows e s showsPrec _ (Sum e f) s = "(" ++ shows e ("+" ++ shows f (")" ++ s)) showsPrec _ (Difference e f) s = "(" ++ shows e ("-" ++ shows f (")" ++ s)) showsPrec _ (Product e f) s = "(" ++ shows e ("*" ++ shows f (")" ++ s)) showsPrec _ (Quotient e f) s = "(" ++ shows e ("/" ++ shows f (")" ++ s)) showsPrec _ (Remainder e f) s = "(" ++ shows e ("%" ++ shows f (")" ++ s)) value (Literal x) = x value (Negated e) = 0 - value e value (Sum e f) = value e + value f value (Difference e f) = value e - value f value (Product e f) = value e * value f value (Quotient e f) = value e `div` value f value (Remainder e f) = value e `mod` value f main = putStrLn (shows e (" == " ++ shows (value e) "")) where e = Product (Difference (Literal 1) (Literal 2)) (Sum (Literal 3) (Literal 4))