-
Notifications
You must be signed in to change notification settings - Fork 22
Description
I propose we introduce new method invocation syntaxes obj.Method.[|arg1; arg2|] for positional arguments and obj.Method.{|name1=val1; name2=val2|} for named arguments.
// Positional arguments
httpClient.GetAsync.[|url; cancellationToken|]
// Named arguments with clean formatting - especially useful for long parameter lists
processData.{|
input = inputData
timeout = 5000
retryCount = 3
enableLogging = true
maxConnections = 100
retryPolicy = exponentialBackoff
timeoutPolicy = circuitBreaker
// ... many more parameters without trailing comma issues
|}
// Eliminates tuple ambiguity
let coords = (x, y, z)
transformPoint.[|x; y; z|] // Three arguments
transformPoint coords // Single tuple argument
transformPoint(x, y, z)The existing way of approaching this problem in F# is using traditional method call syntax:
// Positional arguments - becomes unwieldy with many parameters
obj.Method(arg1, arg2, arg3, arg4, arg5, arg6, arg7, arg8)
// Named arguments - suffers from trailing comma limitations
obj.Method(
param1 = val1,
param2 = val2,
param3 = val3,
param4 = val4, // Trailing comma not allowed!
)Pros and Cons
The advantages of making this adjustment to F# are:
- Eliminates tuple/parameter list ambiguity - Clearly distinguishes between method arguments and tuple parameters
- Solves trailing comma issues - Leverages F#'s optional semicolons for clean vertical formatting
- Improves .NET interop aesthetics - Makes long C#-style API calls more F#-idiomatic
- Consistent with F# data structures - Reuses familiar array
[| |]and record{| |}syntax - Better tooling support - Provides clearer syntax trees for IDE features
- Excellent for long parameter lists - Particularly valuable when dealing with methods that have many parameters, common in .NET libraries
The disadvantages of making this adjustment to F# are:
- Adds new syntax to learn - Developers need to understand these new invocation forms
- Compiler implementation cost - Requires updates to parser, type checker, and codegen
- Tooling updates needed - IDE support (autocomplete, formatting) needs to be updated
- Potential confusion - Some developers might initially confuse with indexers or other constructs
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M-L
This requires parser changes, type checking updates, and IDE tooling support, but builds on existing array/record infrastructure.
Related suggestions: None found after searching existing issues.
Affidavit (please submit!)
Please tick these items 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] This is a language change and not purely a tooling change (e.g. compiler bug, editor support, warning/error messages, new warning, non-breaking optimisation) belonging to the compiler and tooling repository
[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
[x] I have searched both open and closed suggestions on this site and believe this is not a duplicate
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 👍 emoji on this issue. These counts are used to generally order the suggestions by engagement.