[Haskell-cafe] Intro to monad transformers
michael rice
nowgate at yahoo.com
Sun Dec 26 21:21:00 CET 2010
Ok, changed the last line and deleted the bad line. Maybe someone could recommend a better example?
Michael
=============
Prelude> :l test5
[1 of 1] Compiling Main ( test5.hs, interpreted )
test5.hs:16:4:
Occurs check: cannot construct the infinite type: a = Maybe a
When generalising the type(s) for `mplus'
In the instance declaration for `MonadPlus (MaybeT m)'
Failed, modules loaded: none.
--- On Sun, 12/26/10, David Menendez <dave at zednenem.com> wrote:
From: David Menendez <dave at zednenem.com>
Subject: Re: [Haskell-cafe] Intro to monad transformers
To: "michael rice" <nowgate at yahoo.com>
Cc: haskell-cafe at haskell.org
Date: Sunday, December 26, 2010, 2:30 PM
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>
<http://www.eyrie.org/~zednenem/>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20101226/fa9d55e0/attachment.htm>
More information about the Haskell-Cafe
mailing list