[Haskell-cafe] Problem with own written monad
Tillmann Rendel
rendel at rbg.informatik.tu-darmstadt.de
Mon Jan 7 09:56:13 EST 2008
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
More information about the Haskell-Cafe
mailing list