I need to make a function that takes a list and an element and returns a list in which the first occurrence of the element is deleted: something like
removeFst [1,5,2,3,5,3,4,5,6] 5 [1,2,3,5,3,4,5,6]
What I tried:
main :: IO() main = do putStr ( show $ removeFst [1,5,2,3,5,3,4,5,6] 5) removeFst :: [Int] -> Int -> [Int] removeFst [] m = [] removeFst [x] m | x == m = [] | otherwise = [x] removeFst (x:xs) m | x == m = xs | otherwise = removeFst xs m
But that will not work ... it returns a list without the first elements. I think I should make a recursive call to make the list look something like this:
removeFst (x:xs) m | x == m = xs | otherwise = removeFst (-- return the whole list till element x) m
source share