type I a = a;
data Term = Con Int | Div Term Term;
answer, err :: Term;
answer = (Div (Div (Con 1972) (Con 2)) (Con 23));
err = (Div (Con 1)(Con 0));
type M a = State -> (a, State);
type State = Int;
unit :: a -> M a;
unit a = \x -> (a, x);
(★) :: M a -> (a -> M b) -> M b;
m★k = \x -> let (a, y) = m x in let (b, z) = k a y in (b, z);
-- m★k = \x -> let (a, y) = m x in k a y;
tick :: M ();
tick = \x -> ((), x + 1);
eval :: Term -> M Int;
eval (Con a) = unit a;
eval (Div t u) = eval t ★ \a -> eval u ★ \b -> tick★ \_ -> unit (quot a b);
main = print (eval answer 0)
-- > (42,2)