unison/unison-src/transcripts/records.md
2024-06-25 11:11:07 -07:00

2.3 KiB

Ensure that Records keep their syntax after being added to the codebase

scratch/main> builtins.merge
scratch/main> load unison-src/transcripts-using-base/base.u

Record with 1 field

unique type Record1 = { a : Text }
scratch/main> add
scratch/main> view Record1

Record with 2 fields

unique type Record2 = { a : Text, b : Int }
scratch/main> add
scratch/main> view Record2

Record with 3 fields

unique type Record3 = { a : Text, b : Int, c : Nat }
scratch/main> add
scratch/main> view Record3

Record with many fields

unique type Record4 =
  { a : Text
  , b : Int
  , c : Nat
  , d : Bytes
  , e : Text
  , f : Nat
  , g : [Nat]
  }
scratch/main> add
scratch/main> view Record4

Record with many many fields

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]]]]]]]]]]]]]]]]]]]]
}
scratch/main> add
scratch/main> view Record5

Record with user-defined type fields

This record type has two fields whose types are user-defined (Record4 and UserType).

unique type UserType = UserType Nat

unique type RecordWithUserType = { a : Text, b : Record4, c : UserType }
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)

scratch/main> view RecordWithUserType

Syntax

Trailing commas are allowed.

unique type Record5 =
  { a : Text,
    b : Int,
  }