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 <[email protected]> wrote:

From: David Menendez <[email protected]>
Subject: Re: [Haskell-cafe] Intro to monad transformers
To: "michael rice" <[email protected]>
Cc: [email protected]
Date: Sunday, December 26, 2010, 2:30 PM

On Sun, Dec 26, 2010 at 2:00 PM, michael rice <[email protected]> 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 <[email protected]>
<http://www.eyrie.org/~zednenem/>





      
_______________________________________________
Haskell-Cafe mailing list
[email protected]
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to