Difference between revisions of "Solution2.html"
Jump to navigation
Jump to search
(New page: <haskell> parent :: Sheep -> Maybe Sheep parent s = father s `mplus` mother s grandparent :: Sheep -> Maybe Sheep grandparent s = paternalGrandfather s `mplus` paternalGr...) |
(Another definition of grandparent.) |
||
Line 8: | Line 8: | ||
maternalGrandfather s `mplus` |
maternalGrandfather s `mplus` |
||
maternalGrandmother s |
maternalGrandmother s |
||
+ | </haskell> |
||
+ | |||
+ | Alternative grandparent: |
||
+ | <haskell> |
||
+ | grandparent :: Sheep -> Maybe Sheep |
||
+ | grandparent s = (father s >>= parent) `mplus` (mother s >>= parent) |
||
</haskell> |
</haskell> |
Revision as of 14:15, 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 = (father s >>= parent) `mplus` (mother s >>= parent)