Advertisement
Guest User

asd

a guest
Jan 28th, 2015
187
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.80 KB | None | 0 0
  1. data FamilyTree = Void
  2. | Man (String, Int) (FamilyTree) (FamilyTree)
  3. | Female (String, Int) (FamilyTree) (FamilyTree)
  4.  
  5.  
  6. older :: Maybe (String, Int) -> Maybe (String,Int) -> Maybe (String,Int)
  7. older Nothing (Just (a)) = Just (a)
  8. older (Just (a)) Nothing = Just (a)
  9. older (Just (n1,y1)) (Just (n2,y2))
  10. | y1 <= y2 = Just (n1,y1)
  11. | otherwise = Just (n2,y2)
  12.  
  13.  
  14. {-
  15. -}
  16. oldestWoman :: FamilyTree -> Maybe (String,Int)
  17. oldestWoman Void = Nothing
  18. oldestWoman (Man (name, year) Void Void) = Nothing
  19. oldestWoman (Female (name, year) Void Void) = Just (name, year)
  20. oldestWoman (Man (name, year) left right) = older (oldestWoman left) (oldestWoman right)
  21. oldestWoman (Female (name, year) left right) = older (Just (name, year)) (older (oldestWoman left) (oldestWoman right))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement