fsharp / fsharp/fslang-suggestions

Propose new method invocation syntax: obj.Method.[|args|] and obj.Method.{|namedArgs|}

Open
#1,452 3 comments 16 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

probably not
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

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:

  1. Eliminates tuple/parameter list ambiguity - Clearly distinguishes between method arguments and tuple parameters
  2. Solves trailing comma issues - Leverages F#'s optional semicolons for clean vertical formatting
  3. Improves .NET interop aesthetics - Makes long C#-style API calls more F#-idiomatic
  4. Consistent with F# data structures - Reuses familiar array [| |] and record {| |} syntax
  5. Better tooling support - Provides clearer syntax trees for IDE features
  6. 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:

  1. Adds new syntax to learn - Developers need to understand these new invocation forms
  2. Compiler implementation cost - Requires updates to parser, type checker, and codegen
  3. Tooling updates needed - IDE support (autocomplete, formatting) needs to be updated
  4. 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.

Contributor guide

No contributing guide indexed for this repository

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start from the proposed positional and named invocation examples, then review the parser, type checker, code generation, and IDE tooling areas mentioned in the issue. Done would mean a decided language design and coordinated implementation across those areas, with the new syntax handling both argument forms and the stated tuple distinction.

Written by the indexing model from the issue text.

Assessment

Tech stack
fsharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
25/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.