Personal tools

Solution2.html

From HaskellWiki

(Difference between revisions)
Jump to: navigation, search
(Another definition of grandparent.)
Line 13: Line 13:
 
<haskell>
 
<haskell>
 
grandparent :: Sheep -> Maybe Sheep
 
grandparent :: Sheep -> Maybe Sheep
grandparent s = (father s >>= parent) `mplus` (mother s >>= parent)
+
grandparent s = parent s >>= parent
 
</haskell>
 
</haskell>

Revision as of 14:33, 21 September 2012

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 = parent s >>= parent