I want to remove the first occurrence of a given element in a list that has possible duplicates. For example, a list with [1; 6; 1]. I only want to remove 1 once and returns the list [6;1]. My current implementation:
let rec remove l x =
match l with
| [] -> []
| h::t when h = x -> t
| h::t -> h::(remove l h)
this works only for lists that the number I am trying to remove is the first element. For a list like [6; 7; 6] if I wanted to remove the number 7 and return [6; 6]. It does not traverse the list and remove 7 with my current implementation. What can I do to traverse the entire list and remove only the first occurrence of an element?