fslang-suggestions icon indicating copy to clipboard operation
fslang-suggestions copied to clipboard

Applying Curry functions using placeholders in the Wrong Order

Open xp44mm opened this issue 2 years ago • 4 comments

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.

xp44mm avatar Oct 08 '22 07:10 xp44mm

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 avatar Oct 08 '22 09:10 charlesroddie

@charlesroddie this issue is about app expr and is not about lambda expr.

xp44mm avatar Oct 08 '22 10:10 xp44mm

@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).

LyndonGingerich avatar Oct 10 '22 13:10 LyndonGingerich

This suggestion has been closed more than once, including my own.

GratianPlume avatar Oct 11 '22 03:10 GratianPlume

Yeah, this should be closed as a duplicate of #634.

abelbraaksma avatar Oct 22 '22 14:10 abelbraaksma