
7 Jan
2008
7 Jan
'08
9:56 a.m.
Michael Roth wrote:
while trying to learn the secrets of monads, I decided to write a simply monand for pure educational purpose. But it turned out that it isn't as easy as I thought... I circumnavigate quite a number of hurdles but now I reached a point where I'm at a loss. :-(
data Stack a = Stack { run :: [a] -> (a, [a]) }
This definition means that the values in the stack are always of the same type as the values returned by the monadic computation. Try something like data Stack s a = Stack { runStack :: [s] -> (a, [s]) } and instance Monad (Stack s) where ... to thread the same stack through a monadic computation with various intermediate result types, as you probably want. Tillmann