Solution to Exercise 1

A literal translation from do-notation would be:

maternalGrandfather s = mother s >>= \m ->
                        father m

but since the bound variable is used immediately in this function, the equivalent definition is more succinct:

Code available in exercise1.hs
maternalGrandfather :: Sheep -> Maybe Sheep
maternalGrandfather s = mother s >>= father

The other two functions are defined similarly:

Code available in exercise1.hs
fathersMaternalGrandmother :: Sheep -> Maybe Sheep
fathersMaternalGrandmother s = father s >>= mother >>= mother

mothersPaternalGrandfather :: Sheep -> Maybe Sheep
mothersPaternalGrandfather s = mother s >>= father >>= father

Return to exercises.