[Haskell-beginners] All about monads, exercise 4

Nathan Hüsken nathan.huesken at posteo.de
Sun May 1 01:14:21 CEST 2011


Hey,

I am currently reading "All about monads". Unfortanlty I have only a pdf
without the solutions to the exercises.

in the previous exercises I defined:

data Sheep = Sheep (Maybe Sheep) (Maybe Sheep)

father :: Sheep -> Maybe Sheep
father (Sheep f m) = f

mother :: Sheep -> Maybe Sheep
mother (Sheep f m) = m

parent :: Sheep -> Maybe Sheep
parent s = (mother s) `mplus` (father s)

parentList :: Sheep -> [Sheep]
parentList s = (maybeToList (mother s)) `mplus` (maybeToList (father s))

Now I am supposed to combine "parent" and "parentList" to a function
parent :: MonadPlus m => Sheep -> m Sheep

Problem, my parent function relies on "mother" and "father", and they
give a Maybe monad. So I need:
mother :: MonadPlus m => Sheep -> m Sheep

do I not?
But I have no Idea of how the body of this function would look.

Anyone can give me a hint?
Thanks!
Nathan

but what I really need, is a function




More information about the Beginners mailing list