Advertisement
Guest User

Untitled

a guest
Feb 28th, 2020
89
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 0.92 KB | None | 0 0
  1. import Prelude hiding (take, drop)
  2.  
  3. take :: Int -> [a] -> [a]
  4. take 0 _ = []
  5. take n [] = []
  6. take n (x:xs) = x: take (n - 1) xs
  7.  
  8. drop :: Int -> [a] -> [a]
  9. drop 0 xs = xs
  10. drop n [] = []
  11. drop n (x:xs) = drop (n - 1) xs
  12.  
  13. takeDrop :: Int -> [a] -> ([a],[a])
  14. takeDrop 0 xs = ([],xs)
  15. takeDrop n [] = ([],[])
  16. takeDrop n (x:xs) = (x:first,second)
  17. where
  18. (first,second) = takeDrop (n - 1) xs
  19.  
  20.  
  21. --is_elem_of :: a -> [a] -> Bool
  22. is_elem_of element [] = False
  23. is_elem_of element (x:xs) = (x == element) || (is_elem_of element xs)
  24.  
  25. intersection [] _ = []
  26. intersection _ [] = []
  27. intersection (x:xs) (y:ys)
  28. |is_elem_of x (y:ys) = x: intersection xs (y:ys)
  29. |otherwise = intersection xs (y:ys)
  30.  
  31. func [] ys _ _ = []
  32. func (x:xs) ys (z:zs) xs_lst
  33. |is_elem_of x inter = z: func xs ys zs xs_lst
  34. |otherwise = x: func xs ys zs xs_lst
  35. where
  36. inter = intersection xs_lst ys
  37.  
  38. main_func xs ys zs = func xs ys zs xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement