Order of anonymous record types properties #1369
Replies: 1 comment 2 replies
-
That was part of the original design, yeah: https://github.com/fsharp/fslang-design/blob/71cd2e04bc181264a6a68c731ff018369848d1f9/FSharp-4.6/FS-1030-anonymous-records.md#field-ordering
I don't know what the complete rationale was, but it kind of makes sense that F# might do it differently from C#, since anonymous object types in C# can't be expressed across method/function boundaries, while they can in F#. It does make it easier to tell at a glance when inspecting these functions' signatures that they return the same type, for example: let f () = {| A = 1; B = 3; Z = 99 |}
let g () = {| Z = 99; B = 3; A = 1 |} The RFC does however call out the fact that ordering the fields alphabetically may result in mismatches with other orderings: https://github.com/fsharp/fslang-design/blob/71cd2e04bc181264a6a68c731ff018369848d1f9/FSharp-4.6/FS-1030-anonymous-records.md#alternative-do-not-sort-fields-by-name
|
Beta Was this translation helpful? Give feedback.
-
Recently I got this issue on how F# anonyomous record types handle the type property order.
Unlike C# anonymous types, F# creates the definition of anonymous records with properties in alphabetic order which I think is not a usual expected behavior.
The signature shows how the type is internally created.
I believe this takes out control over the type definitions and can cause unexpected behaviors.
Is this an intended behavior? if not, would it be a breaking change?
Beta Was this translation helpful? Give feedback.
All reactions