fsharp / fsharp/fslang-suggestions

Native interop for C#13 params enhancements

Open
#1,377 8 comments 7 reactions 0 assignees View on GitHub
Dominant language
No language data
Stars
373
Forks
21
PR merge metrics
No merged PRs in 30d

Description

**I propose we better interop with the new C# params capabilities**

C# 13 is [enhancing](https://learn.microsoft.com/en-us/dotnet/csharp/language-reference/proposals/params-collections) `params`. It used to only work with arrays:
```csharp
public void WriteNames(params string[] names)
=> Console.WriteLine(String.Join(", ", names));
```

Now it can work with whatever collection:
```csharp
public void WriteNames(params ReadOnlySpan names)
=> Console.WriteLine(String.Join(", ", names));

public void WriteNames(params IEnumerable names)
=> Console.WriteLine(String.Join(", ", names));
```

C# works in the way that the most efficient overload is used on the caller side. Hence
```csharp
WriteNames("Don", "Don");
```
will be resolved to the `ReadOnlySpan` overload, providing the best perf possible in this case.

I propose we allow F# do the same here - automatically pick the best overload.

**The existing way of approaching this problem in F# is**

Currently there is no automagic overload resolution here hence we'd need to construct the collections manually:
```fsharp
WriteNames("Don", "Don") // calls the array overload
WriteNames(["Don"; "Don"]) // calls the IEnumerable overload
WriteNames(ReadOnlySpan([|"Don"; "Don"|])) // calls the ReadOnlySpan overload
```

Not smooth.

## Pros and Cons

**The advantages of making this adjustment to F# are**

Potential perf perks out of the box (with no code adjustments) when moving to a new lang version. Embracing the power of Span.

**The disadvantages of making this adjustment to F# are**

Probably not trivial IL complication.

## Extra information

**Estimated cost (XS, S, M, L, XL, XXL):** S (for someone who understands how params interop works now) or M (for others)

**Related suggestions:** (put links to related suggestions here)

#1267
#1120
#1013

## 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](http://stackoverflow.com)) 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](https://github.com/dotnet/fsharp)
* [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](http://github.com/fsharp/fslang-suggestions/issues) 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 :+1: emoji on this issue. These counts are used to generally order the suggestions by engagement.

Contributor guide

No contributing guide indexed for this repository

Research direction

Start with the linked C# 13 params-collections proposal and related suggestions #1267, #1120, and #1013, then investigate how F# currently handles the overloads shown in the examples. Done would require an agreed language-design approach for selecting among params collection overloads, along with identified implementation and test locations.

Written by the indexing model from the issue text.

Assessment

Tech stack
csharp
Domain
compilers
Issue type
Feature
Difficulty
5/5
Estimated time
Over a week
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
30/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.