|Anonymous | Login | Signup for a new account||2017-08-18 16:37 CEST|
|Main | My View | View Issues | Change Log | Roadmap|
|View Issue Details|
|ID||Project||Category||View Status||Date Submitted||Last Update|
|0002415||OCaml||~DO NOT USE (was: OCaml general)||public||2004-04-06 00:54||2015-12-11 19:04|
|Target Version||Fixed in Version||4.00.0+dev|
|Summary||0002415: feature request - Haskell's $ operator|
|Description||Full_Name: Charles Martin|
Submission from: 220.127.116.11 (18.104.22.168)
Would love to have Haskell's $ operator added to OCaml. Definining it myself as
let ($) f x = f x
doesn't work because of precedence and associativity.
|Tags||No tags attached.|
|Would love to have it too. Simple and useful.|
edited on: 2007-02-22 15:09
Make use of the fact that & is deprecated for logical AND and write:
let ( & ) a b = a b
You can then write
f a b & g c & h 0
or whatever. Also, it can be read as "and" as in "reverse and flatten and fold" etc.
Cool, thanks for the solution...
Will using it from now and kill some parentheses :)
I really like it aswell, can make some code much clearer. Would be nice if the fun call could be optimized away.
edited on: 2007-03-10 18:12
Here is a bit of Camlp4 (compile with the version from CVS) to do that:
$ cat pa_app.ml
[ <:expr@loc< \& $e1$ $e2$ >> -> <:expr@loc< $e1$ $e2$ >>
| e -> e ]))#str_item;
$ ocamlc -pp camlp4rf -c -I +camlp4 pa_app.ml
$ camlp4o ./pa_app.cmo -str "f a b & g c & h 0"
f a b (g c (h 0))
|This feature was implemented by Xavier Clerc in 3.12.1+dev and I backported it to trunk in commit r12070.|
Can the feature also include defining the actual function/operator, not just the compiler primitive? From what I've been able to see, one hasn't been defined in pervasives.
And whilst (&) is deprecated, I'd recommend against using this, as it conflicts with jocaml.
Is there any reason ocaml can't add the ($) operator (and change the needed precedence/associativity rules)?
There is a very good reason not to change the associativity for ($):
lots of people already use it in their code, for various applications.
It has the right associativity if you use it for left-to-right composition
Moreover, $ is used by camlp4, so it cannot be reserved for something else.
If you are ready to use 2-character combinations, there are plenty of possibilities.
|2005-11-18 10:13||administrator||New Issue|
|2007-02-21 10:43||ertai||Note Added: 0003919|
|2007-02-22 15:08||johnwhitington||Note Added: 0003938|
|2007-02-22 15:09||johnwhitington||Note Edited: 0003938|
|2007-02-22 15:26||ertai||Note Added: 0003939|
|2007-03-10 10:29||dbuenzli||Note Added: 0003970|
|2007-03-10 18:11||ertai||Note Added: 0003971|
|2007-03-10 18:12||ertai||Note Edited: 0003971|
|2012-03-20 10:32||lefessan||Note Added: 0007108|
|2012-03-20 10:32||lefessan||Status||acknowledged => resolved|
|2012-03-20 10:32||lefessan||Fixed in Version||=> 4.00.0+dev|
|2012-03-20 10:32||lefessan||Resolution||open => fixed|
|2012-03-20 10:32||lefessan||Assigned To||=> lefessan|
|2012-05-18 05:52||jessicah||Note Added: 0007441|
|2012-05-18 08:30||garrigue||Note Added: 0007442|
|2015-12-11 19:04||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|