
In article
I assume there is a standard name for this class/function:
instance Foo [] where foo [] = mzero foo (x:_) = return x
instance Foo (Maybe x) where foo Nothing = mzero foo Just x = return x
I don't believe so. I had to write my own classes to do this sort of thing. This is also a good opporunity to point out an ambiguity in the standard MonadPlus class. All instances satisfy these: mplus mzero a = a mplus a mzero = a But only some instances (such as []) satisfy this: (mplus a b) >>= c = mplus (a >>= c) (b >>= c) Other instances (IO, Maybe) satisfy this: mplus (return a) b = return a I think mplus should be separated into two functions. This code shows the difference a bit more clearly: do b <- mplus (return True) (return False) if b then mzero else return () For the first kind this is the same as "return ()", for the second kind it's the same as "mzero". -- Ashley Yakeley, Seattle WA