Solution2.html

From HaskellWiki
Revision as of 14:15, 21 September 2012 by Gphilip (talk | contribs) (Another definition of grandparent.)

Jump to: navigation, search
parent :: Sheep -> Maybe Sheep
parent s = father s `mplus` mother s

grandparent :: Sheep -> Maybe Sheep
grandparent s = paternalGrandfather s `mplus` 
                paternalGrandmother s `mplus` 
                maternalGrandfather s `mplus` 
                maternalGrandmother s

Alternative grandparent:

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