You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
a readonly struct{| F = FooReadOnly<int>.Empty |}
b struct readonly {| F = FooReadOnly<int>.Empty |}
c readonly {| F = FooReadOnly<int>.Empty |}// 'byrefLike' implies struct
a byref readonly struct{| R = ReadOnlySpan<int>.Empty |}
b struct byref readonly {| R = ReadOnlySpan<int>.Empty |}
c byreflike readonly struct{| R = ReadOnlySpan<int>.Empty |}
Structness inference could capture both IsByRefLike and IsReadOnly:
f {| R = ReadOnlySpan<int>.Empty |}// Only works if the input type is byref-like and readonly
Pros and Cons
Advantages:
Parity with records
Allows you to use these more ephemeral constructs in the perf-sensitive environments ByRefLike structs are intended for
Disadvantages:
I can't think of an explicit instantiation syntax that doesn't kind of suck
This can make an input parameter heavy syntax-wise
These kinds of structs are done with attributes in F# today, but to enable them for anonymous records would require a keyword due to the lack of support for attributes on function parameters
Allowing a keyword instead of an attribute is inconsistent with how you define ByRefLike structs today in F#
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Affidavit (please submit!)
Please tick this by placing a cross in the box:
This is not a question (e.g. like one you might ask on stackoverflow) and I have searched stackoverflow for discussions of this issue
This is not something which has obviously "already been decided" in previous versions of F#. If you're questioning a fundamental design decision that has obviously already been taken (e.g. "Make F# untyped") then please don't submit it.
Please tick all that apply:
This is not a breaking change to the F# language design
I or my company would be willing to help implement and/or test this
The text was updated successfully, but these errors were encountered:
I propose we allow ByRefLike and ReadOnly struct anonymous records.
You can create struct anonymous records as such today:
However, there is no ability to make them ByRefLike, which means you cannot have them contain other ByRefLike structs such as
Span<'T>
.A possible declaration syntax might look like this:
It would be sort of nonsense to have you require an attribute to instantiate one, so a keyword would likely be needed:
Or perhaps structness inference would take care of the instantiation site:
Similarly, there is no way to define a
IsReadOnly
struct anonymous record. Possible declaration syntax:And an instantiation syntax:
Declaration syntax options for having both:
Instantiation syntax for having both:
Structness inference could capture both
IsByRefLike
andIsReadOnly
:Pros and Cons
Advantages:
Disadvantages:
Extra information
Estimated cost (XS, S, M, L, XL, XXL): M
Affidavit (please submit!)
Please tick this by placing a cross in the box:
Please tick all that apply:
The text was updated successfully, but these errors were encountered: