Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions FSharp-4.5/FS-1053-span.md
Original file line number Diff line number Diff line change
Expand Up @@ -336,6 +336,8 @@ in some situations where capture must be avoided.
* Cannot be static or instance members of a class or normal struct
* 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.


Here is an example:
```fsharp
Expand Down