I propose we have a way to produce (i.e. not necessarily consume from within F#) type parameters that are covariant/contravariant, per .NET's rules (allowed only in input/output positions, respectively).
Custom attributes could be used for this purpose, such as:
type IEnumerable<[<Out>] 'T> =
abstract member GetEnumerator : unit -> IEnumerator<'T>
and IEnumerator<[<Out>] 'T> =
abstract member Current : 'T with get
I chose to abuse InAttribute and OutAttribute for this purpose here, since .NET disallows them on type parameters (F# would have to treat them as allowed) and they look similar to C#'s syntax and thus are broadly understandable. Of course different attributes could be used for this purpose too.
The existing way of approaching this problem in F# is none; maybe via (unsafe) IL rewriting to add the necessary flags.
Pros and Cons
The advantages of making this adjustment to F# are parity with other .NET languages in terms of quality of type hierarchies, improving interoperability with such languages.
The disadvantages of making this adjustment to F# are having a feature that cannot be used from within F# itself (in company with CLIMutable etc.)
Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: #162
Affidavit (please submit!)
Please tick these items 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.
I propose we have a way to produce (i.e. not necessarily consume from within F#) type parameters that are covariant/contravariant, per .NET's rules (allowed only in input/output positions, respectively).
Custom attributes could be used for this purpose, such as:
I chose to abuse
InAttributeandOutAttributefor this purpose here, since .NET disallows them on type parameters (F# would have to treat them as allowed) and they look similar to C#'s syntax and thus are broadly understandable. Of course different attributes could be used for this purpose too.The existing way of approaching this problem in F# is none; maybe via (unsafe) IL rewriting to add the necessary flags.
Pros and Cons
The advantages of making this adjustment to F# are parity with other .NET languages in terms of quality of type hierarchies, improving interoperability with such languages.
The disadvantages of making this adjustment to F# are having a feature that cannot be used from within F# itself (in company with
CLIMutableetc.)Extra information
Estimated cost (XS, S, M, L, XL, XXL): S
Related suggestions: #162
Affidavit (please submit!)
Please tick these items 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.