What is the standard way to remove an item from a list in OCaml?

In general, lisp we can use the remove function.

Does OCaml seem to have no such method?

+7
source share
1 answer

Lists in OCaml are immutable. Therefore, you cannot remove things from them. Usually you create another list that does not have what you do not want. You must use List.filter .

If you absolutely need to have mutable lists, you can. There is something in Batteries called a Dllist that might look like what you want. (This is a double-linked list, however, unlike the Lisp list).

One of the great things about OCaml, in my opinion, is that a purely functional subset is really quite efficient. I have never had to use modified lists in my own projects.

+14
source

All Articles