[Haskell-cafe] Building pattern and trying monads

Yves Parès yves.pares at gmail.com
Mon May 28 20:16:04 CEST 2012


Actually, I think the backtracking property here stems more from the
MonadPlus StateT instance than from the properties of Maybe.
(mplus a b runs a and b by passing explicitely the same state to them).

2012/5/28 Roman Cheplyaka <roma at ro-che.info>

> * Yves Parès <yves.pares at gmail.com> [2012-05-28 11:28:22+0200]
> > > observe $ flip runStateT 10 $ (put 0 >> mzero) <|> modify (+3)
> > >   ((),13)
> >
> > If the only thing you need is backtracking, using LogicT might be a
> little
> > overkill, using Maybe in the bottom of you monad stack suits just fine:
> >
> > case flip runStateT 10 $ (put 0 >> mzero) <|> modify (+3) of
> >     Just x -> ....
> >     Nothing -> ....
>
> Indeed, I didn't realise that Maybe may be (no pun intended) sufficient
> here!
>
> --
> Roman I. Cheplyaka :: http://ro-che.info/
>
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/haskell-cafe/attachments/20120528/6bd53754/attachment.htm>


More information about the Haskell-Cafe mailing list