how do you delete the nth element in a list in Haskell

I wrote a pretty intuitive recursive approach:

remove :: Int -> [a] -> [a]
remove _ [] = []
remove 0 (x:xs) = xs
remove n (x:xs) = x : remove (n-1) (xs)

Take into account that I am considering the first element to be index 0.
Let me know if you have any doubts.

Leave a Comment