dotnet / dotnet/docs

SRTP Member Constraint Invocation Syntax is not documented

Open
#27,240 0 comments 1 reaction 0 assignees View on GitHub
dotnet-fsharp/svc
Dominant language
No language data
Stars
4.8k
Forks
6.1k
Avg merge
15h 21m
Merged PRs (30d)
370

Description

F# language guide refers to Statically Resolved Type Parameters at three locations, under Types and Inference.

[Generics](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/#statically-resolved-type-parameters)
[Constraints](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/constraints)
[Statically Resolved Type Parameters](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters)

The first two of the above documents do not provide an example of invoking a member defined by the constraining mechanism.
The last of the above documents provides an example which makes use of the invocation of a member function, but there's no explanation for the syntax used.

The F# Language spec section 6.8.4 is titled Member Constraint Invocation Expressions, but that section does not provide an explanation of the syntax either. There is an explanation of how the invocation takes place, with a focus on type inference, but the explanation does not include any details regarding the expression that is applied to the constraint, i.e. `expr` in `(static-typars : (member-sig) expr)`

My current understanding of how to invoke members is based on various snippets of code I found such as
https://stackoverflow.com/questions/13011811/f-generic-type-constraints-and-duck-typing
https://stackoverflow.com/questions/37680758/how-do-you-define-this-statically-resolved-type-parameter
https://github.com/fsharp/fslang-suggestions/issues/440

Given that constraining a type to have a member is highly likely associated to an intention to call that member, it would be helpful if the Statically Resolved Type Parameters link above explained how invocation can be specified, and what the correct syntax is. For example, the first stackoverflow link does not use a tuple for invoking the getter of a property and the compiler is OK with this. When calling a static member, the tuple contains only parameters, and no instance is needed, or so I think etc.

Clarifying these in the documents would help users truly make use of this language feature.

---
#### Document Details

⚠ *Do not edit this section. It is required for docs.microsoft.com ➟ GitHub issue linking.*

* ID: 7d56dc27-d3f4-2ac1-0cd1-61d06fb8e314
* Version Independent ID: 1abc963d-0fa8-a313-0637-e99dd67064ed
* Content: [Statically Resolved Type Parameters - F#](https://docs.microsoft.com/en-us/dotnet/fsharp/language-reference/generics/statically-resolved-type-parameters)
* Content Source: [docs/fsharp/language-reference/generics/statically-resolved-type-parameters.md](https://github.com/dotnet/docs/blob/main/docs/fsharp/language-reference/generics/statically-resolved-type-parameters.md)
* Product: **dotnet-fsharp**
* GitHub Login: @cartermp
* Microsoft Alias: **dotnetcontent**

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.