module skeleton12 import StdEnv import StdMaybe :: BM a b = {t :: a -> b, f :: b -> a} bm :: BM a a bm = {f=id, t=id} :: Expr a = Lit a | (+.) infixl 6 (Expr a) (Expr a) | (*.) infixl 6 (Expr a) (Expr a) | Read | Write (Expr Int) | XOR (Expr Bool) (Expr Bool) | Not (Expr Bool) | E.b: Eq (Expr b) ( Expr b) & == b | Throw | Try (Expr a) (Expr a) class show a :: a [String] -> [String] instance show (Expr a) where show (Lit x) l = [toString x:l] show (x1 +. x2) l = show x1 ["+":show x2 l] show (x1 *. x2) l = show x1 ["*":show x2 l] show Read l = ["Read":l] show (Write x) l = ["Write (":show x [")":l]] show (XOR x1 x2) l = show x1 ["XOR":show x2 l] show (Not x) l = ["Not":show x l] show (Eq x1 x2) l = show x1 ["==":show x2 l] show Throw l = ["throw":l] show (Try x1 x2) l = ["Try":show x1 ["Except":show x2 l]]