Revision as of 02:01, 23 August 2012 by Pronate
If the compiler cannot guess which MonadPlus to use you will need to specify it when the function is called. So,
parent :: MonadPlus m => Sheep -> m Sheep parent s = (toMonad (father s)) `mplus` (toMonad (mother s)) grandparent :: MonadPlus m => Sheep -> m Sheep grandparent s = (toMonad (parentalGrandfather s)) `mplus` (toMonad (parentalGrandmother s)) `mplus` (toMonad (maternalGrandfather s)) `mplus` (toMonad (maternalGrandmother s)) toMonad :: MonadPlus m => Maybe a -> m a toMonad Nothing = mzero toMonad (Just s) = return s
will use the Maybe monad and either
parent someSheep :: Maybe Sheep
parent someSheep ::  Sheep
will use the list monad.
parent someSheep :: [Sheep]