[Haskell-cafe] Intro to monad transformers

Daniel Fischer daniel.is.fischer at googlemail.com
Sun Dec 26 22:07:01 CET 2010


On Sunday 26 December 2010 21:21:00, michael rice wrote:
> 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.
>
>


>     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".

Actually, it should be

    case maybe_value of
      Nothing -> runMaybeT y
      _ -> return maybe_value



More information about the Haskell-Cafe mailing list