[Haskell-cafe] YAHT: searchAll5

Nicolas Frisby nicolas.frisby at gmail.com
Mon Oct 30 23:45:15 EST 2006


Disclaimer: I've never read through YAHT, so I don't know if I'm
missing any context...

Your intuition was correct: you do want to lift the MonadPlus property
through the StateT transformer. This is the key to the transformer
libraries, each transformer both contributes a computational feature
(MonadState, MonadReader, MonadPlus, MonadError, ...) as well as
maintains all features of the monad it's transforming.

You've noticed that we need an instance in order to have the StateT
monad transformer maintain the MonadPlus property of its inner monad.

Beyond the encouragement that your intuition was dead on, I would
suggest tryng to use mzero and mplus sooner than you are doing so. In
other words, your method defintions should be simpler.

Good luck!
Nick

On 10/30/06, Magnus Therning <magnus at therning.org> wrote:
> I can't get searchAll5[1] in Yet Another Haskell Tutorial to run.  Ghci
> complains that it can't find a MonadPlus that satisfies the required
> type; it needs a MonadPlus.
>
> I suspect this is due to the use of 'mzero' and 'mplus', without making
> StateT a MonadPlus.  My thought for this was to "push" mzero into the
> inner monad and have 'mplus' pass on to the inner monad:
>
>   instance Monad m => MonadPlus (StateT state m) where
>       mzero = StateT (\s -> return (s, mzero))
>       (StateT m1) `mplus` (StateT m2) = StateT (\s -> do
>           (s1, a) <- m1 s
>           (s2, b) <- m2 s1
>           return (s2, a `mplus` b))
>
> What's above isn't accepted by ghci, and I don't even know for sure that
> my thought makes sense.
>
> /M
>
> [1]: http://en.wikibooks.org/wiki/Haskell/YAHT/Monads#Monad_Transformers
>
> --
> Magnus Therning                             (OpenPGP: 0xAB4DFBA4)
> magnus at therning.org             Jabber: magnus.therning at gmail.com
> http://therning.org/magnus
>
> Software is not manufactured, it is something you write and publish.
> Keep Europe free from software patents, we do not want censorship
> by patent law on written works.
>
> Finagle's Fifth Law:
> Always draw your curves, then plot your readings.
>
>
> _______________________________________________
> Haskell-Cafe mailing list
> Haskell-Cafe at haskell.org
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>
>
>
>


More information about the Haskell-Cafe mailing list