

do f = f bind.





do monad f = f (head monad).

return monad = tail monad.





putLine l = if l then

doIO {

putChar (head l);

putLine (tail l)

}

else

returnIO 0.





returnStateT monad x s = return monad (x:s).

bindStateT monad m k s = bind monad (m s) (\as -> k (head as) (tail as)).

doStateT monad f = f (bindStateT monad).

-- Actually construct the transformed monad.

StateT monad = bindStateT monad : returnStateT monad.





prog = do (StateT State) {

liftStateT State (modify (plus 1));

a modifyT State (plus 10);

b liftStateT State $ put (a+b);

c return (StateT State) $ c+1

}.

