unison/unison-src/transcripts/records.md

139 lines
2.3 KiB
Markdown
Raw Permalink Normal View History

2024-04-15 02:57:08 +03:00
Ensure that Records keep their syntax after being added to the codebase
```ucm:hide
scratch/main> builtins.merge
scratch/main> load unison-src/transcripts-using-base/base.u
```
## Record with 1 field
```unison:hide
unique type Record1 = { a : Text }
```
```ucm:hide
scratch/main> add
```
```ucm
scratch/main> view Record1
```
## Record with 2 fields
```unison:hide
unique type Record2 = { a : Text, b : Int }
```
```ucm:hide
scratch/main> add
```
```ucm
scratch/main> view Record2
```
## Record with 3 fields
```unison:hide
unique type Record3 = { a : Text, b : Int, c : Nat }
```
```ucm:hide
scratch/main> add
```
```ucm
scratch/main> view Record3
```
## Record with many fields
```unison:hide
2024-04-15 02:57:08 +03:00
unique type Record4 =
{ a : Text
, b : Int
, c : Nat
, d : Bytes
, e : Text
, f : Nat
, g : [Nat]
}
```
```ucm:hide
scratch/main> add
```
```ucm
scratch/main> view Record4
```
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
scratch/main> add
2024-03-05 22:50:16 +03:00
```
```ucm
scratch/main> view Record5
2024-03-05 22:50:16 +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
scratch/main> add
```
If you `view` or `edit` it, it _should_ be treated as a record type, but it does not (which is a bug)
```ucm
scratch/main> view RecordWithUserType
```
## Syntax
Trailing commas are allowed.
```unison
2024-04-15 02:57:08 +03:00
unique type Record5 =
{ a : Text,
b : Int,
}
```