Skip to content
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

Add %revapply as a primitive (for infix pipe) #5236

Closed
vicuna opened this issue Mar 7, 2011 · 4 comments
Closed

Add %revapply as a primitive (for infix pipe) #5236

vicuna opened this issue Mar 7, 2011 · 4 comments

Comments

@vicuna
Copy link

vicuna commented Mar 7, 2011

Original bug ID: 5236
Reporter: till
Assigned to: @xclerc
Status: closed (set by @xavierleroy on 2013-08-31T10:44:28Z)
Resolution: fixed
Priority: normal
Severity: feature
Version: 3.12.0
Fixed in version: 3.12.1+dev
Category: ~DO NOT USE (was: OCaml general)
Monitored by: bitbckt "Dmitry Grebeniuk" dario @ygrek bobot thelema @hcarty @dbuenzli yminsky @oandrieu

Bug description

One emerging idiom (at least in jane street's code base) is to define a pipe operator to string computations as such:

let (|>) x f = f x

This, sadly, does come with a performance hit (enough that we've actually seriously considered ). The attached patch introduces a new primitive (%revapply) that can be used to define |>:

external (|>) : 'a -> ('a -> 'b) -> 'b = "%revapply"

Feedback and comments would be greatly appreciated.

File attachments

@vicuna
Copy link
Author

vicuna commented Mar 8, 2011

Comment author: @dbuenzli

I also use this in various places in my code (it often shows up in combinator approaches). Can't comment on the performance hit though.

@vicuna
Copy link
Author

vicuna commented Apr 17, 2011

Comment author: thelema

This solution, while workable, doesn't seem like the right way to do this. What about improving the inliner to inline function composition/application structures (like this and (fun f g x -> g (f x)), etc) in general?

@vicuna
Copy link
Author

vicuna commented Jan 19, 2012

Comment author: @lefessan

I modified the fix (SVN commit r12055 in version/3.12):

  • it should now print correctly the location
  • non-unary functions are also optimized (before, they would be partially applied twice).

@vicuna
Copy link
Author

vicuna commented Jan 19, 2012

Comment author: @hcarty

Will this be included in trunk/3.13 as well?

@vicuna vicuna closed this as completed Aug 31, 2013
dra27 pushed a commit to dra27/ocaml that referenced this issue Feb 27, 2021
 Previous fix would introduce applications without correct locations. Also,
non-unary functions would not be correctly optimized (this is fixed in
Simplif.simplify_exits). Added one test in the testsuite.



git-svn-id: http://caml.inria.fr/svn/ocaml/version/3.12@12055 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant