-- Hutton's Razor in CPS import Control.Monad.Cont data Expr = Val Int | Add Expr Expr | TVal Bool | Ite Expr Expr Expr type Stack = [Int] type Con = Cont Stack Stack add :: Stack -> Stack add (m : n : s) = (m + n) : s add _ = error "oops" ite :: Stack -> Stack ite (0 : _ : e : s) = e : s ite (1 : e : _ : s) = e : s ite _ = error "gee whiz" eval :: Expr -> Con -> Con eval (Val n) c = (n :) <$> c eval (TVal True) c = (1 :) <$> c eval (TVal False) c = (0 :) <$> c eval (Add x y) c = add <$> eval x (eval y c) eval (Ite b x y) c = ite <$> eval b (eval x (eval y c))