Home / Learn / 4 Kinds

Release v0.4.0Edition 0.2

4.9 Recap and reference

Page 10 of 10

4.9.1 For agents

una --json check . prints each diagnostic with its code, message, primary span and repairs; una --json test . prints each example's outcome. U2004 and U2026 carry exact edits, which una fix . applies: the field's label, and the constraint [T: Eq]. U2007's repair names the missing variant, but the arm's value depends on intent, so add it by hand. U1001, U2001, U2009 and U2025 depend on intent. The compact rule: a record builds with every field labeled; a sum lists its variants with |, and one of a single variant starts with |; a when over a sum matches every variant or ends with else; a public generic function writes the constraint its body needs.

4.9.2 Recap

  • kind Parcel with indented fields is a record: build it with every field labeled, and read a field with a dot.
  • A record never changes: to change a field, build a new record from the old one.
  • Records are nominal: two kinds with the same fields are two types. An alias, kind Sku = Text, is the type it names.
  • kind Zone = Local | National | Abroad is a sum; a variant may carry fields, and a sum of one variant starts with |.
  • value is AtLocker tests the variant and gives a Bool.
  • when takes a sum apart: one arm per variant, each binding the fields it uses, or else for the rest.
  • Leave out else where each variant needs its own answer: a new variant is then reported.
  • Generic kinds and functions take type parameters, [T], with the weakest constraint the body needs.

4.9.3 Reference

Next:5 Contracts and the verifier