data Term = Con Int | Div Term Term; data M a = Raise Exception | Return a; type Exception = String; answer, err :: Term; answer = (Div (Div (Con 1972) (Con 2)) (Con 23)); err = (Div (Con 1)(Con 0)); eval :: Term -> M Int; eval (Con a) = Return a; eval (Div t u) = case eval t of Raise e -> Raise e; Return a -> case eval u of Raise e -> Raise e; Return b -> if b == 0 then Raise "divide by zero" else Return (quot a b); sh :: M Int -> String; sh (Raise e) = e; sh (Return a) = show a; main = print ((sh (eval answer)) ++ "; " ++(sh (eval err))) -- > "42; divide by zero"