New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
please add List.cons #4714
Comments
Comment author: @dbuenzli I also needed this function really more than once. Daniel |
Comment author: @damiendoligez First, :: is a constructor and in general in OCaml, you cannot use a constructor name as a shorthand for one the corresponding construction functions. For example: let x = (::) (1, []);; |
Comment author: @dbuenzli Yes but what we need is to use as a function and you cannot do that. See the following toplevel session :
( < );;
( :: );;Error: Syntax error (::);;Error: Syntax error Thus the need for List.cons e.g. to pass to folding functions. Best, Daniel |
Comment author: @damiendoligez You cannot do that for any constructor. Why is there a particular need for :: ? |
Comment author: @dbuenzli 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. Best, Daniel |
Comment author: @gasche List.cons should be included in 4.03. |
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
Bug 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 :-)
The text was updated successfully, but these errors were encountered: