OCaml cons (::) operator?

11

No. Cons (::) is a constructor, constructors can not be infix operators. The allowed infix symbols are here:

http://caml.inria.fr/pub/docs/manual-caml-light/node4.9.html

Some workarounds are (as you mention) the verbose

(fun x l -> x :: l)

and defining your own nontraditional infix cons

let (+:) x l = x :: l

Leave a Comment