Guest User

Untitled

a guest
Jan 22nd, 2018
62
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.44 KB | None | 0 0
  1. count:: [a] -> Int
  2. count [] = 0
  3. count (x:xs) = 1 + count xs
  4.  
  5. _count:: Num b => b -> [a] -> b
  6. _count b [] = b
  7. _count b (x:xs) = _count (b + 1) xs
  8.  
  9. count:: [a] -> Int
  10. count = _count 0
  11.  
  12. myfold:: (b -> a -> b) -> b -> [a] -> b
  13. myfold f b [] = b
  14. myfold f b (x:xs) = myfold f (f b x) xs
  15.  
  16. count = myfold incr 0
  17. where incr c _ = c + 1
  18.  
  19. myfoldr:: (a -> b -> b) -> b -> [a] -> b
  20. myfoldr f b [] = b
  21. myfoldr f b (x:xs) = f x (myfoldr f b xs)
Add Comment
Please, Sign In to add comment