Monaden mit Null

import Control.Monad ( guard )
do a <- [ 1 .. 4 ] 
   b <- [ 2 .. 3 ]
   guard $ even (a + b)
   return ( a * b )
Definition:
guard f = if f then return () else mzero
Wirkung:
guard f >>= \ () -> m = if f then m else mzero
konkrete Implementierung:
class Monad m => MonadPlus m where 
    mzero :: m a ; ...
instance MonadPlus [] where mzero = []



Johannes Waldmann 2011-01-18