Skip to content

Conversation

@T-Gro
Copy link
Contributor

@T-Gro T-Gro commented Aug 26, 2024

Click “Files changed” → “⋯” → “View file” for the rendered RFC.

* Cannot be captured by any closure construct (async methods or lambda expressions)
* Cannot be used as a generic parameter
- In F# 9 and higher, this restriction is relaxed if the generic parameter is defined in C# using the `allows ref struct` anti-constraint. F# can instantiate such generics in types and methods with byref-like types. As a few examples, this affects BCL delegate types (`Action<>`,`Func<>`), interfaces (`IEnumerable<>`,`IComparable<>`) and generic arguments with a user-provided accumulator function (`String.string Create<TState>(int length, TState state, SpanAction<char, TState> action)`)
- It is impossible to author generic code supporting byref-like types in F#.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Would it be worth expanding on this here? E.g., to mention that the allows ref struct anti-constraint is not automatically propagated in the same way as normal generic constraints, with some examples.

let a : Action<'T> =let f (x : 'T) = a.Invoke x // Can 'T be ReadOnlySpan<int> here? Presumably not?
let f (g : Action<'T>) (x : 'T) = g.Invoke x // Can 'T be ReadOnlySpan<int> here?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It is not automatically propagated, this makes sense to expand on - thanks for checking this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants