Hi I am trying to implement the function drop in haskell the thing is that I
I have been trying for some time and I came up with this code where I am
trying to do recursion:
drop :: Integer -> [Integer] -> [Integer]
drop 0 (x:xs) = (x:xs)
drop n (x:xs)
|n < lList (x:xs) = dropN (n-1) xs :
|otherwise = []
drop :: Integer -> [a] -> [a]
drop n xs | n < 1 = xs
drop _ [] = []
drop n (_:xs) = drop (n-1) xs
Line 1: It specifies that drop will accept an Integer and a list, and return a list;
Line 2: If n < 1, the function will return the list as it is (this pattern is matched if you're dropping 0 or -2 elements, for example);
Line 3: No matter what Integer has been passed to the function, if the list passed is empty, an empty list will be returned as well;
Line 4: Dropping n elements from a list is equivalent to dropping n-1 elements from the tail (xs) of that same list.
HTH
Antonio
--