Advertisement
juaniisuar

Untitled

Jun 19th, 2018
370
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.30 KB | None | 0 0
  1. filter f [] = []
  2. filter f [x] = if f x then [x] else []
  3. filter f (x:xs) = let (x',xs') = filter f [x] ||| (filter f xs) in x'++xs'
  4.  
  5. map f [] = []
  6. map f [x] = f x
  7. map f (x:xs) = let (x',xs') = f x ||| (map f xs) in x':xs'
  8.  
  9. {-
  10. -- Not actually better
  11.  
  12. tabulateAux f l r | (r - l) < 1 = []
  13. | otherwise = let mid = div (r + l) 2
  14. (l',r') = tabulateAux f l mid ||| tabulateAux f (mid+1) r
  15. in l' ++ [f mid] ++ r'
  16.  
  17. tabulate f n | n <= 0 = []
  18. | otherwise = tabulateAux f 0 n
  19.  
  20. -}
  21.  
  22. tabulateAux f i n | i == n = []
  23. | otherwise = let (l,r) = (f i) ||| (tabulateAux f (i+1) n) in l:r
  24.  
  25. tabulate f n | n <= 0 = []
  26. | otherwise = tabulateAux f 0 n
  27.  
  28.  
  29. showt [] = EMPTY
  30. showt [x] = ELT x
  31. showt s = let mid = div (length s) 2
  32. (l,r) = take mid s ||| drop mid s
  33. in NODE l r
  34.  
  35. showl [] = NIL
  36. showl (x:xs) = CONS x xs
  37.  
  38. join = concat
  39.  
  40. contraer f [] = []
  41. contraer f [x] = [x]
  42. contraer f (x:y:xs) = let (x':xs') = f x y ||| contraer f xs in x':xs'
  43.  
  44. reduce f e [] = e
  45. reduce f e [x] = x
  46. reduce f e s@(x:y:xs) = reduce f e (contraer f s)
  47.  
  48. expansion f [] _ = []
  49. expansion f _ [] = []
  50. expansion f (x:xs) [y] = x : [f x y]
  51. expansion f (x:xs) (y:y':ys) = x : (f x y) : expansion f xs ys
  52.  
  53. scan f e [] = ([],e)
  54. scan f e [x] = ([x],e)
  55. scan f e s =
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement