fsharp / fsharp/fslang-suggestions
Allow specifying subset of type arguments explicitly
- Dominant language
- No language data
- Stars
- 373
- Forks
- 21
- PR merge metrics
- No merged PRs in 30d
Description
**Submitted by Tomas Petricek on 5/28/2014 12:00:00 AM**
**7 votes on UserVoice prior to migration**
Say we have a generic type Frame. When using instance methods of the frame, it is possible to write a generic method that takes a single additional type parameter - for example, to get a column as a specific type:
``` fsharp
frame.GetColumn("Value")
```
However, doing the same thing using module and function is not possible, because the corresponding `getCol` function requires three type arguments (TRow, TCol and the additional one):
``` fsharp
frame |> Frame.getCol<_, _, float> "Value"
```
It would be nice if F# had some mechanism that would allow specifying only subset of the type parameters. For example:
``` fsharp
let getCol<[] 'T, 'TCol, 'TRow> frame = (...)
```
And then I could write just:
``` fsharp
frame |> Frame.getCol "Value"
```
Interestingly, this is also problem for extension methods. When you define a C#-style extension method for a generic type like frame, it also has three type arguments and it is impossible to call it with just a single type argument.
---
Alternatively, allow for auto-inferrable generic parameters expressed like this
```fsharp
Foo<'a, [] 'b, [] 'c when 'a :> Bar<'b,'c>>(v:'a) = class end
```
Then only `Foo` is required at each use site and the other generic parameters are optional. `Foo` would always be shorthand for `Foo`
In certain situations where wildcards are not allowed, solving the type parameters must be possible "immediately". Exactly what that means technically would be TBD.
**[Original UserVoice Submission](https://fslang.uservoice.com/forums/245727-f-language/suggestions/5980924)**
[Archived Uservoice Comments](../tree/master/archive/suggestion-5980924-allow-specifying-subset-of-type-arguments-explici.md#comments)
Contributor guide
No contributing guide indexed for this repository
Assessment
This issue has not been assessed yet.