Advertisement
Guest User

Untitled

a guest
Nov 13th, 2018
114
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. reverse1 :: [t] -> [t]
  2. reverse1 [] = []
  3. reverse1 xs =  foldr (\x s-> s ++ [x]) [] xs
  4.  
  5. remove :: Eq t => [t] -> [t] -> [t]
  6. remove _ [] = []
  7. remove [] [x] = [x]
  8. remove xs ys = foldr (\x acc -> if elem x xs then acc else x : acc) [] ys
  9.  
  10. sumsq :: Int -> Int
  11. sumsq y = foldr (\x acc-> x^2 + acc) 0 [1..y]
  12.  
  13. myFilter :: (t -> Bool) -> [t] -> [t]
  14. myFilter f [] = []
  15. myFilter f xs = foldr (\x acc-> if (f x) == False then acc else x : acc) [] xs
  16.  
  17. myLength :: [t] -> Int
  18. myLength [] = 0
  19. myLength xs = foldr (\x acc-> 1 + acc) 0 xs
  20.  
  21. minList :: [Int] -> Int
  22. minList [] = 0
  23. minList xs = foldr1 (\x y-> if x >= y then y else x) xs
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement