Advertisement
Guest User

Untitled

a guest
Dec 8th, 2016
88
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. data Food = Apple | Orange | Carrot | Potato
  2.  
  3. sumCond :: Food -> (Int, Int) -> (Int, Int)
  4. {-
  5. sumCond Apple   (f, v) = (f + 1, v)
  6. sumCond Orange  (f, v) = (f + 1, v)
  7. sumCond Carrot  (f, v) = (f, v + 1)
  8. sumCond Potato (f, v) = (f, v + 1)
  9. -}
  10. sumCond food (f, v) = case food of Apple -> (f + 1, v)
  11.                                    Orange -> (f + 1, v)
  12.                                    Carrot -> (f, v + 1)
  13.                                    Potato -> (f, v + 1)
  14.  
  15. sumFood :: [Food] -> (Int, Int)
  16. sumFood xs = foldl (\x y -> sumCond y x) (0, 0) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement