[Haskell-cafe] Intro to monad transformers
dave at zednenem.com
Sun Dec 26 20:30:23 CET 2010
On Sun, Dec 26, 2010 at 2:00 PM, michael rice <nowgate at yahoo.com> wrote:
> instance Monad m => MonadPlus (MaybeT m) where
> mzero = MaybeT $ return Nothing
> mplus x y = MaybeT $ do maybe_value <- runMaybeT x
> case maybe_value of
> Nothing -> runMaybeT y
> Just value -> runMaybeT x
The last line is wrong. It should be, "Just value -> return value". But that
doesn't cause the problem.
> instance Show (MaybeT m a)
This is never valid. You've defined show, shows, and showsPrec in terms of
each other, creating unbounded recursion. Delete it.
> *Main> askPassword
> Loading package transformers-0.2.2.0 ... linking ... done.
> *** Exception: stack overflow
This triggers the unbounded recursion, when it tries to show askPassword.
Note that there is no way to show IO values, so there's no way to show
MaybeT IO values.
Instead, use runMaybeT askPassword
Dave Menendez <dave at zednenem.com>
-------------- next part --------------
An HTML attachment was scrubbed...
More information about the Haskell-Cafe