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

Comments

Projects
None yet
1 participant
@vicuna
Copy link

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

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

This comment has been minimized.

Copy link
Author

commented Jan 19, 2012

Comment author: @hcarty

Will this be included in trunk/3.13 as well?

@vicuna vicuna closed this Aug 31, 2013

@vicuna vicuna added the feature-wish label Mar 20, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.