Advertisement
Guest User

Untitled

a guest
Sep 15th, 2019
107
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.83 KB | None | 0 0
  1. --
  2. sumCustom :: (Num a) => [a] -> a
  3. sumCustom [] = 0
  4. sumCustom (x:xs) = x + sumCustom xs
  5. --
  6. (<+>) :: [a] -> [a] -> [a]
  7. (<+>) [] xs = xs
  8. (<+>) (x:xs) ys = x : (xs <+> ys)
  9. --
  10. reverseCustom :: [a] -> [a]
  11. reverseCustom [] = []
  12. reverseCustom (x:xs) = reverseCustom xs <+> [x]
  13. --
  14. initCustom :: [a] -> [a]
  15. initCustom [] = error "Empty list"
  16. initCustom (x:[]) = []
  17. initCustom (x:xs) = x: initCustom xs
  18. --
  19. lastCustom :: [a] -> a
  20. lastCustom [] = error "Empty list"
  21. lastCustom (a:[]) = a
  22. lastCustom (x:xs) = lastCustom xs
  23. --
  24. initsCustom :: [a] -> [[a]]
  25. initsCustom [] = error "Empty list"
  26. initsCustom (x:[]) = [[x]]
  27. initsCustom (x:xs) = initsCustom(initCustom(x:xs)) <+> [x:xs]
  28. --
  29. tailsCustom :: [a] -> [[a]]
  30. tailsCustom [] = error "Empty list"
  31. tailsCustom (x:[]) = [[x]]
  32. tailsCustom (x:xs) = [x:xs] <+> tailsCustom(xs)
  33. --
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement