Original bug ID: 4714 Reporter: ecc Assigned to:@gasche Status: closed (set by @xavierleroy on 2016-12-07T10:48:59Z) Resolution: fixed Priority: normal Severity: feature Version: 3.11.0 Fixed in version: 4.03.0+dev / +beta1 Category: ~DO NOT USE (was: OCaml general) Monitored by:@dbuenzli
Since :: is treated specially, one cannot use ( :: ) as a shorthand for the function (fun x y -> x :: y). It would be convenient to define List.cons to be this function, complementing List.hd and List.tl.
(Unless this would be offensive to les francophones, in which case another name would be fine :-)
The text was updated successfully, but these errors were encountered:
First, :: is a constructor and in general in OCaml, you cannot use a constructor name as a shorthand for one the corresponding construction functions.
Second, :: only looks special because it is an infix symbol, but like any other infix symbol, if you enclose it in parentheses it is parsed as a prefix symbol.
You cannot do that for any constructor. Why is there a particular need for :: ?
Since the function definition is only a few characters, it's not clear that we'll
want to "pollute" the stdlib namespace in this case. We'll have to argue it
between the OCaml developers to make a decision.
While it is at first suprising that (::) cannot be used as a function as the other operators allow, I don't really care about this. But having List.cons instead of (fun a b -> a :: b) could be nice and more readable in certain cases; I know I missed it a few times.
OTOH, for (left) folds List.cons wouldn't be in the right order anyway.