-- The three statements below beginning "type" may be omitted -- but the code is then more fragile. data Term = Con Int | Div Term Term; type M a = State -> (a, State); type State = Int; 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) x = (a, x); eval (Div t u) x = let (a, y) = eval t x in let (b, z) = eval u y in (div a b, z+1); main = print (eval answer 0) -- > (42,2)