Real World Haskell

Real World Haskell Bryan O'Sullivan John Goerzen Don Stewart pub. O'Reilly 2009 (OreillyAndAssociates) (AnimalBook)

ISBN 9780596514983 (See IsbnThirteenBug) http://oreilly.com/catalog/9780596514983/

Also available on line: The newest, best, easiest and free-est way to learn HaskellLanguage. http://book.realworldhaskell.org/read/
Plus in HaskellLanguage monads.

On p.362-364 of this book, the authors introduce the notion of mplus withing a monad, with the comment on p.364 that The name mplus does not imply addition.

I had found this very confusing as an implementation I was looking at did something which was not addition and I could not understand why.

Does anyone know why plus is used for something which is not addition?

I have found this: http://www.haskell.org/haskellwiki/MonadPlus

Light is dawning. I have found the following on http://monads.haskell.cz/html/laws.html :


Continuing to use the Maybe monad as an example, we see that the Maybe monad is an instance of MonadPlus:

 instance MonadPlus Maybe where
    mzero             = Nothing
    Nothing `mplus` x = x
    x `mplus` _       = x

This identifies Nothing as the zero value and says that adding two Maybe values together gives the first value that is not Nothing. If both input values are Nothing, then the result of mplus is also Nothing.

So it is a logical addition rather than a numerical one.

It is good to talk things through even with people who are not listening yet. Another example of HowWikiWorks.

-- JohnFletcher
The title is an oxymoron :-P thanks
CategoryHaskell CategoryBook

EditText of this page (last edited October 22, 2013) or FindPage with title or text search