sepp2k remarks on concept lists is an important thing to understand; such as map , filter , foldr , etc., process all elements of the list evenly, and it is important to understand what information is available at each step, and how the result of each step is combined with other steps.
But the aspect that I want to emphasize is that I think that you really should try to solve these problems in terms of library functions. Adapting the solution from this older answer of mine to your problem:
deleteFirst x xs = beforeX ++ afterX -- Split the list into two pieces: -- * prefix = all items before first x -- * suffix = all items after first x where (beforeX, xAndLater) = break (/=x) xs afterX = case xAndLater of [] -> [] (_:xs) -> xs
The trick is that break already has built-in "before the first hit" behavior. As an additional exercise, you can try writing your own version of break ; learning to write these small, general, and reusable functions is always useful.
source share