fslang-suggestions
fslang-suggestions copied to clipboard
Applying Curry functions using placeholders in the Wrong Order
Use the placeholder (for example underscore _
) to partially apply the Curry function, and the argument at the placeholder will be provided later.
What if we have a curried function of three arguments:
let stringify a b c = sprintf "%s%s%s" a b c
and we want to supply the first and last arguments, leaving the middle one for later?
["";(*some string data*)]
|> List.map(stringify "a" _ "c")
It is equivalent to
["";(*some string data*)]
|> List.map(fun x -> stringify "a" x "c")
You can also use the placeholder more than once in a call. For example, what if wanted to supply only the last argument?
Map ["","";(*some string data*)]
|> Map.map(stringify _ _ "c")
It is equivalent to
Map ["","";(*some string data*)]
|> Map.map(fun k v -> stringify k v "c")
In order to be compatible with the existing syntax, it is recommended that the placeholder should not be last when Curry functions are applied. for example don't like stringify "1" _ _
Pros and Cons
The advantages of making this adjustment to F# are ...
- more readable
- All the advantages of a point-free style
- More convenient application to operators. for example
(-) _ 1
The disadvantages of making this adjustment to F# are ...
- It only applies to the immediate arguments of Curry function, and cannot be applied to child element of a argument.
Extra information
Estimated cost (XS, S, M, L, XL, XXL):
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
- [x] This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
- [x] I have searched both open and closed suggestions on this site and believe this is not a duplicate
- [x] This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
- [x] This is not a breaking change to the F# language design
- [ ] I or my company would be willing to help implement and/or test this
For Readers
If you would like to see this issue implemented, please click the :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.
I have searched both open and closed suggestions on this site and believe this is not a duplicate
I would suggest doing this
This post is a comment on https://github.com/fsharp/fslang-suggestions/issues/634 but read the thread and linked ones first.
@charlesroddie this issue is about app expr and is not about lambda expr.
@xp44mm In that thread, they were also discussing a similar syntax to this. If not a fun
, your syntax is still conceptually a lambda (or something like one, anyway; I'm not seeing distinct boundaries in definition between the two).
This suggestion has been closed more than once, including my own.
Yeah, this should be closed as a duplicate of #634.