Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the standard way to remove element from a list in OCaml?

Tags:

ocaml

In common lisp, we can use the remove function.

It seems there is no such a method in OCaml ?

like image 865
z_axis Avatar asked Nov 10 '11 06:11

z_axis


1 Answers

Lists in OCaml are immutable. So you can't remove things from them. You normally create another list that doesn't have the things you don't want. For this, you would use List.filter.

If you absolutely have to have mutable lists, you can. In Batteries there is something called a Dllist that might be like what you want. (It is a doubly linked list, however, unlike a Lisp list).

One of the great things about OCaml, in my opinion, is that the pure functional subset is really quite effective. I've never needed to use mutable lists in my own projects.

like image 137
Jeffrey Scofield Avatar answered Sep 17 '22 21:09

Jeffrey Scofield