Mantis Bug Tracker

View Issue Details Jump to Notes ] Issue History ] Print ]
IDProjectCategoryView StatusDate SubmittedLast Update
0002415OCamlOCaml generalpublic2004-04-06 00:542012-05-18 13:45
Reporteradministrator 
Assigned Tolefessan 
PrioritynormalSeverityfeatureReproducibilityalways
StatusresolvedResolutionfixed 
PlatformOSOS Version
Product Version 
Target VersionFixed in Version4.00.0+dev 
Summary0002415: feature request - Haskell's $ operator
DescriptionFull_Name: Charles Martin
Version:
OS:
Submission from: 65.57.245.11 (65.57.245.11)


FEATURE REQUEST

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.

Charles

TagsNo tags attached.
Attached Files

- Relationships

-  Notes
(0003919)
ertai (developer)
2007-02-21 10:43

Would love to have it too. Simple and useful.
(0003938)
johnwhitington (reporter)
2007-02-22 15:08
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.

(0003939)
ertai (developer)
2007-02-22 15:26

Cool, thanks for the solution...

Will using it from now and kill some parentheses :)
(0003970)
dbuenzli (reporter)
2007-03-10 10:29

I really like it aswell, can make some code much clearer. Would be nice if the fun call could be optimized away.

Daniel
(0003971)
ertai (developer)
2007-03-10 18:11
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
open Camlp4.PreCast;
AstFilters.register_str_item_filter
  (Ast.map_expr
    (fun
     [ <: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))

(0007108)
lefessan (developer)
2012-03-20 10:32

This feature was implemented by Xavier Clerc in 3.12.1+dev and I backported it to trunk in commit r12070.
(0007441)
jessicah (reporter)
2012-05-18 05:52

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)?
(0007442)
garrigue (manager)
2012-05-18 08:30

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
for instance.
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.

- Issue History
Date Modified Username Field Change
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


Copyright © 2000 - 2011 MantisBT Group
Powered by Mantis Bugtracker