Skip to content

Commit ebb3d39

Browse files
CopilotBillWagner
andauthored
Remove misleading nominal types section from F# anonymous records documentation (#49288)
* Initial plan * Remove misleading nominal types section from anonymous records article Co-authored-by: BillWagner <[email protected]> * Add ai-usage frontmatter to anonymous-records.md Co-authored-by: BillWagner <[email protected]> --------- Co-authored-by: copilot-swe-agent[bot] <[email protected]> Co-authored-by: BillWagner <[email protected]>
1 parent 667b56f commit ebb3d39

File tree

1 file changed

+2
-24
lines changed

1 file changed

+2
-24
lines changed

docs/fsharp/language-reference/anonymous-records.md

Lines changed: 2 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
title: Anonymous Records
33
description: Learn how to construct and use anonymous records, a language feature that helps with the manipulation of data.
44
ms.date: 11/04/2021
5+
ai-usage: ai-assisted
56
---
67
# Anonymous Records
78

@@ -181,29 +182,6 @@ let data3 = struct {| data2 with Z = r2.X |}
181182

182183
Anonymous records have a number of characteristics that are essential to fully understanding how they can be used.
183184

184-
### Anonymous records are nominal
185-
186-
Anonymous records are [nominal types](https://en.wikipedia.org/wiki/Nominal_type_system). They are best thought of as named [record](records.md) types (which are also nominal) that do not require an up-front declaration.
187-
188-
Consider the following example with two anonymous record declarations:
189-
190-
```fsharp
191-
let x = {| X = 1 |}
192-
let y = {| Y = 1 |}
193-
```
194-
195-
The `x` and `y` values have different types and are not compatible with one another. They are not equatable and they are not comparable. To illustrate this, consider a named record equivalent:
196-
197-
```fsharp
198-
type X = { X: int }
199-
type Y = { Y: int }
200-
201-
let x = { X = 1 }
202-
let y = { Y = 1 }
203-
```
204-
205-
There isn't anything inherently different about anonymous records when compared with their named record equivalents when concerning type equivalency or comparison.
206-
207185
### Anonymous records use structural equality and comparison
208186

209187
Like record types, anonymous records are structurally equatable and comparable. This is only true if all constituent types support equality and comparison, like with record types. To support equality or comparison, two anonymous records must have the same "shape".
@@ -255,7 +233,7 @@ Anonymous records have some restrictions in their usage. Some are inherent to th
255233

256234
Anonymous records do not support pattern matching, unlike named records. There are three reasons:
257235

258-
1. A pattern would have to account for every field of an anonymous record, unlike named record types. This is because anonymous records do not support structural subtyping – they are nominal types.
236+
1. A pattern would have to account for every field of an anonymous record, unlike named record types. This is because anonymous records do not support structural subtyping – they require exact field matching.
259237
2. Because of (1), there is no ability to have additional patterns in a pattern match expression, as each distinct pattern would imply a different anonymous record type.
260238
3. Because of (2), any anonymous record pattern would be more verbose than the use of “dot” notation.
261239

0 commit comments

Comments
 (0)