[Haskell-cafe] Re: what is inverse of mzero and return?

Ashley Yakeley ashley at semantic.org
Sun Jan 23 06:06:21 EST 2005


In article <200501230458.57938.jadrian at mat.uc.pt>,
 Jorge Adriano Aires <jadrian at mat.uc.pt> wrote:

> One common example is using MonadPlus for some backtracking algorithm, then 
> instantiatiating it to Maybe or List instance depending on wether you just 
> want one solution or all of them. 

Backtracking only works with the first kind, even if you're only 
interested in the first solution. This must hold:

  (mplus a b) >>= c = mplus (a >>= c) (b >>= c)

My test code is a backtracking example:

  do
    b <- mplus (return True) (return False)
    if b then mzero else return ()

> [*] For instance, I've missed Maybe being an instance of MonadError. 

You could define your own instance, of course.

-- 
Ashley Yakeley, Seattle WA



More information about the Haskell-Cafe mailing list