Difference between revisions of "Solution2.html"
Jump to navigation
Jump to search
(Explained an incorrect solution,) |
|||
Line 10: | Line 10: | ||
</haskell> |
</haskell> |
||
+ | This solution will not work. If the sheep has a father and only a maternal grandparent, this function will return Nothing: |
||
− | Alternative grandparent: |
||
<haskell> |
<haskell> |
||
grandparent :: Sheep -> Maybe Sheep |
grandparent :: Sheep -> Maybe Sheep |
Revision as of 17:49, 10 June 2013
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
This solution will not work. If the sheep has a father and only a maternal grandparent, this function will return Nothing:
grandparent :: Sheep -> Maybe Sheep
grandparent s = parent s >>= parent