-
Notifications
You must be signed in to change notification settings - Fork 21
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Clarify status of SRTP constructor constraints #1068
Comments
I would either keep it straightforward:
or maybe, since F# constructors are first-class functions, we could treat it as such?
but it looks very implicit and it's probably annoying to parse. However, what about keeping the I can't think of a reason other than truly extreme microoptimization, why one would want a purely inlined constraint instead of a .NET one. However, such a specialized scenario could be served via an equally specialized attribute on the type parameter ( BTW, this part of the proposal is a little confusing:
However, as noted above (and as I just tested in Ionide), typing |
Any updates? Will we be able to write? type InteropModuleFactory<'InteropModule when 'InteropModule : (new : IJSObjectReference -> 'InteropModule)> (jsRuntime: IJSRuntime) = |
No updates at this point |
+1 for SRTP constructor constraint to be able to support arbitrary parameters in types, not just unit |
I propose we clarify status of "SRTP constructor constraints".
The F# language spec defines
These are very different things though they look related in syntax. In types:
The first is an F# SRTP member constraint and the second a "real" .NET constraint emitted as .NET metadata. The first requires
inline
, the second doesn't. The corresponding standard invocation at callsites is as follows:These correspond to
AddCxMethodConstraint
andAddCxTypeMustSupportDefaultCtor
in the implementation.The problem is that the status of "SRTP constructor constraints" is left unspecified. In types these are actually disallowed:
That indicates the intent of F# 2.0 was to disallow these. However in implementations a corresponding check is missing and they can arise:
Note the printing is different and uses
.ctor
- that's because this is an "SRTP constructor constraint". and not a .NET default constructor constraint. These constraints are also not checked in the same way as .NET default constructor constraints, for example there is no requirement that the return type be the same as the type being constrained, leading to nonsense code like this;We need to clarify the status of these constraints in the F# language - given that they can already arise we should allow them. If they are allowed, then decide how they can be written in types and signatures. Note the syntax
when ^a : (new : unit -> ^a)
is not available because it is used for .NET default constructor constraintsProposal:
The syntax
^a : (new : unit -> ^a)
continues to be reserved for .NET default constructor constraintsWe find a new syntax e.g
^a : (member ``.ctor`` : unit -> ^a)
is used for SRTP constructor constraintsWe give a warning to require this syntax at existing implementation calls, so
gives a warning with a recommendation to become
No syntax for these constraints is perfect given that the
when ^a : (new : unit -> ^a)
syntax is already taken, and can't really be changed toPros and Cons
The advantages of making this adjustment to F# are to make the language uniform and allow all inferred signatures to be written.
The disadvantages of making this adjustment to F# are none
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: (put links to related suggestions here)
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
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.
The text was updated successfully, but these errors were encountered: