Skip to content

Commit cafa2b0

Browse files
authored
Add FS-1008 (#81)
1 parent a6975c1 commit cafa2b0

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

spec/rfc-status.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@
1818
| F# 4.1 | FS-1005 | [Underscores in Numeric Literals](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1005-underscores-in-numeric-literals.md) | [completed](https://github.com/fsharp/fslang-spec/pull/29/commits/2bd80c8cdb2f89ccadc9dac038568d3089d8e1dc) |
1919
| F# 4.1 | FS-1006 | [Struct Tuples](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1006-struct-tuples.md) | [completed](https://github.com/fsharp/fslang-spec/pull/30/commits) |
2020
| F# 4.1 | FS-1007 | [Additional Option Module Functions](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1007-additional-Option-module-functions.md) | This specifies some details of the `FSharp.Core` library, which is not part of this spec (except for the basic items listed in [§18](https://fsharp.github.io/fslang-spec/the-f-library-fsharpcoredll/)) |
21-
| F# 4.1 | FS-1008 | [Struct Records](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1008-struct-records.md) | |
21+
| F# 4.1 | FS-1008 | [Struct Records](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1008-struct-records.md) | [completed](https://github.com/fsharp/fslang-spec/pull/81) |
2222
| F# 4.1 | FS-1009 | [Mutually Referential Types and Modules in Single Scope](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1009-mutually-referential-types-and-modules-single-scope.md) | |
2323
| F# 4.1 | FS-1010 | [Add Map.count](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1010-add-map-count.md) | This specifies some details of the `FSharp.Core` library, which is not part of this spec (except for the basic items listed in [§18](https://fsharp.github.io/fslang-spec/the-f-library-fsharpcoredll/)) |
2424
| F# 4.1 | FS-1012 | [Caller Info Attributes](https://github.com/fsharp/fslang-design/tree/main/FSharp-4.1/FS-1012-caller-info-attributes.md) | [completed](https://github.com/fsharp/fslang-spec/pull/74) |

spec/type-definitions.md

Lines changed: 17 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -490,6 +490,8 @@ be given the `AbstractClass` attribute.
490490

491491
Record types are implicitly marked serializable unless the `AutoSerializable(false)` attribute is used.
492492

493+
Record types are reference types unless the `Struct` attribute is used (see [§](type-definitions.md#struct-type-definitions)).
494+
493495
### Members in Record Types
494496

495497
Record types may declare members ([§](type-definitions.md#members)), overrides, and interface implementations. Like all types
@@ -1255,17 +1257,17 @@ because the size of `BadStruct2` would be infinite:
12551257

12561258
```fsharp
12571259
[<Struct>]
1258-
type BadStruct 2 =
1260+
type BadStruct2 =
12591261
val data : float;
1260-
val rest : BadStruct 2
1262+
val rest : BadStruct2
12611263
new (data, rest) = { data = data; rest = rest }
12621264
```
12631265

12641266
Likewise, the implied size of the following struct would be infinite:
12651267

12661268
```fsharp
12671269
[<Struct>]
1268-
type BadStruct 3 (data : float, rest : BadStruct 3 ) =
1270+
type BadStruct3 (data : float, rest : BadStruct3 ) =
12691271
member s.Data = data
12701272
member s.Rest = rest
12711273
```
@@ -1295,6 +1297,18 @@ abnormal value.
12951297
Public struct types for use from other CLI languages should be designed with the
12961298
existence of the default zero-initializing constructor in mind.
12971299

1300+
[Record Type Defintions](#record-type-definitions) may also use the `[<Struct>]` attribute to change their representation from a reference type to a value type:
1301+
1302+
```fsharp
1303+
[<Struct>]
1304+
type Vector3 = { X: float; Y: float; Z: float }
1305+
```
1306+
1307+
Record structs have the following limitations:
1308+
1309+
- Unlike normal F# structs you cannot call the default constructor
1310+
- When marked with `[<CLIMutable>]` attribute, a default constructor is not created because it already exists implicitly
1311+
12981312
## Enum Type Definitions
12991313

13001314
Occasionally the need arises to represent a type that compiles as a CLI enumeration type. An _enum

0 commit comments

Comments
 (0)