Home / Learn / 2 Numbers

Release v0.4.0Edition 0.2

2.8 Recap and reference

Page 9 of 9

2.8.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. U0007 carries an exact edit, the literal rewritten, which una fix . applies. U5001 gives a counterexample and repairs that are descriptions only (a guard, a wider type, a wrapping or saturating method). U0101, U1001, U1002, U2001 and U2022 depend on intent, so they carry no repair. The compact rule: Int is unbounded and exact, with Euclidean / and mod; money is Int cents; every division by a value that is not a nonzero literal, and every operation or narrowing on U8…U64, I8…I64, is a proof obligation; types never convert implicitly.

2.8.2 Recap

  • Every value has a type. print takes a Text; put a number into one with braces: "{units} units".
  • let name = value names a value; let name: Type = value also states its type. A body makes each name once.
  • Int is a whole number of any size, so a sum or a product is exact.
  • Keep money in Int cents, and divide last: order * 15 / 100.
  • *, / and mod come before + and -, left to right; parentheses change the order.
  • / and mod are Euclidean. A divisor that may be zero is refuted with a counterexample.
  • A fixed-width type, such as U8, is for a number of a set size. Every operation on it is proved to fit; wrapping and saturating are methods.
  • Integer types never mix: convert with to_int(), or narrow with to_u8() and its proof.

2.8.3 Reference

Next:3 Text and conditions