Difference between revisions of "Solution3.html"

From HaskellWiki
Jump to: navigation, search
(Another solution.)
m (Contents transferred to single solutions page)
 
Line 22: Line 22:
   
 
</haskell>
 
</haskell>
  +
  +
[[Category:Pages to be removed]]

Latest revision as of 08:44, 9 April 2021

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