Difference between revisions of "Solution3.html"

From HaskellWiki
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)) ...)
 
m (Contents transferred to single solutions page)
 
(One intermediate revision by one other user not shown)
Line 10: Line 10:
   
 
</haskell>
 
</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>
  +
  +
[[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