Difference between revisions of "Solution3.html"
Jump to navigation
Jump to search
(New page: <haskell> parent :: Sheep -> [Sheep] parent s = (maybeToList (mother s)) ++ (maybeToList (father s)) grandparent :: Sheep -> [Sheep] grandparent s = (maybeToList (paternalGrandfather s)) ...) |
(Another solution.) |
||
Line 8: | Line 8: | ||
(maybeToList (maternalGrandfather s)) ++ |
(maybeToList (maternalGrandfather s)) ++ |
||
(maybeToList (maternalGrandmother s)) |
(maybeToList (maternalGrandmother s)) |
||
+ | |||
+ | </haskell> |
||
+ | |||
+ | Alternate solution: |
||
+ | |||
+ | <haskell> |
||
+ | parent :: Sheep -> [Sheep] |
||
+ | parent s = (maybeToList $ mother s) `mplus` (maybeToList $ father s) |
||
+ | |||
+ | grandparent :: Sheep -> [Sheep] |
||
+ | grandparent s = parent s >>= parent |
||
+ | |||
</haskell> |
</haskell> |
Revision as of 14:32, 21 September 2012
parent :: Sheep -> [Sheep]
parent s = (maybeToList (mother s)) ++ (maybeToList (father s))
grandparent :: Sheep -> [Sheep]
grandparent s = (maybeToList (paternalGrandfather s)) ++
(maybeToList (paternalGrandmother s)) ++
(maybeToList (maternalGrandfather s)) ++
(maybeToList (maternalGrandmother s))
Alternate solution:
parent :: Sheep -> [Sheep]
parent s = (maybeToList $ mother s) `mplus` (maybeToList $ father s)
grandparent :: Sheep -> [Sheep]
grandparent s = parent s >>= parent