|Anonymous | Login | Signup for a new account||2017-09-21 21:36 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0004714||OCaml||~DO NOT USE (was: OCaml general)||public||2009-02-11 20:08||2016-12-07 11:48|
|Target Version||Fixed in Version||4.03.0+dev / +beta1|
|Summary||0004714: please add List.cons|
|Description||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 :-)
|Tags||No tags attached.|
|I also needed this function really more than once. Daniel|
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.
For example: let x = (::) (1, );;
Yes but what we need is to use as a function and you cannot do that. See the following toplevel session :
Objective Caml version 3.11.0
# ( < );;
- : 'a -> 'a -> bool = <fun>
# ( :: );;
Error: Syntax error
Error: Syntax error
Thus the need for List.cons e.g. to pass to folding functions.
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.
|List.cons should be included in 4.03.|
|2009-02-11 20:08||ecc||New Issue|
|2009-02-12 01:38||dbuenzli||Note Added: 0004837|
|2009-03-16 15:18||doligez||Note Added: 0004856|
|2009-03-16 15:18||doligez||Status||new => acknowledged|
|2009-03-20 11:34||dbuenzli||Note Added: 0004859|
|2009-03-20 14:59||doligez||Note Added: 0004860|
|2009-03-20 17:57||dbuenzli||Note Added: 0004861|
|2015-04-26 23:06||gasche||Note Added: 0013733|
|2015-04-26 23:06||gasche||Status||acknowledged => resolved|
|2015-04-26 23:06||gasche||Fixed in Version||=> 4.03.0+dev / +beta1|
|2015-04-26 23:06||gasche||Resolution||open => fixed|
|2015-04-26 23:06||gasche||Assigned To||=> gasche|
|2016-12-07 11:48||xleroy||Status||resolved => closed|
|2017-02-23 16:36||doligez||Category||OCaml general => -OCaml general|
|2017-03-03 17:55||doligez||Category||-OCaml general => -(deprecated) general|
|2017-03-03 18:01||doligez||Category||-(deprecated) general => ~deprecated (was: OCaml general)|
|2017-03-06 17:04||doligez||Category||~deprecated (was: OCaml general) => ~DO NOT USE (was: OCaml general)|
|Copyright © 2000 - 2011 MantisBT Group|