2024-04-15 02:57:08 +03:00
|
|
|
Ensure that Records keep their syntax after being added to the codebase
|
2021-09-14 18:21:37 +03:00
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> builtins.merge
|
|
|
|
scratch/main> load unison-src/transcripts-using-base/base.u
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Record with 1 field
|
|
|
|
|
|
|
|
```unison:hide
|
|
|
|
unique type Record1 = { a : Text }
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view Record1
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Record with 2 fields
|
|
|
|
|
|
|
|
```unison:hide
|
|
|
|
unique type Record2 = { a : Text, b : Int }
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view Record2
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Record with 3 fields
|
|
|
|
|
|
|
|
```unison:hide
|
|
|
|
unique type Record3 = { a : Text, b : Int, c : Nat }
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view Record3
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
## Record with many fields
|
|
|
|
|
|
|
|
```unison:hide
|
2024-04-15 02:57:08 +03:00
|
|
|
unique type Record4 =
|
2021-09-14 18:21:37 +03:00
|
|
|
{ a : Text
|
|
|
|
, b : Int
|
|
|
|
, c : Nat
|
|
|
|
, d : Bytes
|
|
|
|
, e : Text
|
|
|
|
, f : Nat
|
|
|
|
, g : [Nat]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view Record4
|
2021-09-14 18:21:37 +03:00
|
|
|
```
|
2022-09-26 22:12:21 +03:00
|
|
|
|
2024-03-05 22:50:16 +03:00
|
|
|
## Record with many many fields
|
|
|
|
|
|
|
|
```unison:hide
|
|
|
|
unique type Record5 = {
|
|
|
|
zero : Nat,
|
|
|
|
one : [Nat],
|
|
|
|
two : [[Nat]],
|
|
|
|
three: [[[Nat]]],
|
|
|
|
four: [[[[Nat]]]],
|
|
|
|
five: [[[[[Nat]]]]],
|
|
|
|
six: [[[[[[Nat]]]]]],
|
|
|
|
seven: [[[[[[[Nat]]]]]]],
|
|
|
|
eight: [[[[[[[[Nat]]]]]]]],
|
|
|
|
nine: [[[[[[[[[Nat]]]]]]]]],
|
|
|
|
ten: [[[[[[[[[[Nat]]]]]]]]]],
|
|
|
|
eleven: [[[[[[[[[[[Nat]]]]]]]]]]],
|
|
|
|
twelve: [[[[[[[[[[[[Nat]]]]]]]]]]]],
|
|
|
|
thirteen: [[[[[[[[[[[[[Nat]]]]]]]]]]]]],
|
|
|
|
fourteen: [[[[[[[[[[[[[[Nat]]]]]]]]]]]]]],
|
|
|
|
fifteen: [[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]],
|
|
|
|
sixteen: [[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]],
|
|
|
|
seventeen: [[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]],
|
|
|
|
eighteen: [[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]],
|
|
|
|
nineteen: [[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]],
|
|
|
|
twenty: [[[[[[[[[[[[[[[[[[[[Nat]]]]]]]]]]]]]]]]]]]]
|
|
|
|
}
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2024-03-05 22:50:16 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view Record5
|
2024-03-05 22:50:16 +03:00
|
|
|
```
|
|
|
|
|
2023-06-14 19:58:18 +03:00
|
|
|
## Record with user-defined type fields
|
|
|
|
|
|
|
|
This record type has two fields whose types are user-defined (`Record4` and `UserType`).
|
|
|
|
|
|
|
|
```unison:hide
|
|
|
|
unique type UserType = UserType Nat
|
|
|
|
|
|
|
|
unique type RecordWithUserType = { a : Text, b : Record4, c : UserType }
|
|
|
|
```
|
|
|
|
|
|
|
|
```ucm:hide
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> add
|
2023-06-14 19:58:18 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
If you `view` or `edit` it, it _should_ be treated as a record type, but it does not (which is a bug)
|
|
|
|
|
|
|
|
```ucm
|
2024-06-12 01:22:09 +03:00
|
|
|
scratch/main> view RecordWithUserType
|
2023-06-14 19:58:18 +03:00
|
|
|
```
|
|
|
|
|
|
|
|
|
2022-09-26 22:12:21 +03:00
|
|
|
## Syntax
|
|
|
|
|
|
|
|
Trailing commas are allowed.
|
|
|
|
|
|
|
|
```unison
|
2024-04-15 02:57:08 +03:00
|
|
|
unique type Record5 =
|
|
|
|
{ a : Text,
|
2022-09-26 22:12:21 +03:00
|
|
|
b : Int,
|
|
|
|
}
|
|
|
|
```
|