Literals

A literal expression is a basic form of Unison expression. Unison has the following types of literals:

  • A 64-bit unsigned integer of type Nat (which stands for natural number__) consists of digits from 0 to 9. The smallest Nat is 0 and the largest is 18446744073709551615. * You can also write Nat numbers in their hex format 0x, as in 0x003 for 3. * A__64-bit signed integer of type Int consists of a natural number immediately preceded by either + or -. For example, 4 is a Nat, whereas +4 is an Int. The smallest Int is -9223372036854775808 and the largest is +9223372036854775807.
  • A 64-bit floating point number of type Float consists of an optional sign (''+''/''-''), followed by two natural numbers separated by .. Floating point literals in Unison are IEEE 754-1985 double-precision numbers. For example 1.6777216 is a valid floating point literal.
  • A text literal of type Text is any sequence of Unicode characters between pairs of quotes, """ Multi-line text literals are supported with the triple quote syntax """. The escape character is \, so a quote character can be included in a text literal with the escape sequence \". The full list of escape sequences is given in the Escape Sequences section below. For example, "Hello, World!" is a text literal. A text literal can span multiple lines. Newlines do not terminate text literals, but become part of the literal text.
  • A character literal of type Char consists of a ? character marker followed by a single Unicode character, or a single escape sequence. For example, ?a, ?🔥 or ?\t.
  • There are two Boolean literals__: true and false, and they have type Boolean. * A__byte literal starts with 0xs. For example 0xsdeadbeef
  • A hash literal begins with the character #. See the section Hashes for details on the lexical form of hash literals. A hash literal is a reference to a term or type. The type or term that it references must have a definition whose hash digest matches the hash in the literal. The type of a hash literal is the same as the type of its referent. #a0v829 is an example of a hash literal.
  • A literal list has the general form [v1, v2, … vn] where v1 through vn are expressions. A literal list may be empty. For example, [], ["x"], and [1, 2, 3] are list literals. The expressions that form the elements of the list all must have the same type. If that type is T, then the type of the list literal is .base.List T or [T].
  • A function literal or lambda has the form p1 p2 … pn -> e, where p1 through pn are regular identifiers and e is a Unison expression (the body of the lambda). The variables p1 through pn are local variables in e, and they are bound to any values passed as arguments to the function when it’s called (see the section Function Application for details on call semantics). For example x -> x Nat.+ 2 is a function literal.
  • A tuple literal has the form (v1,v2, …, vn) where v1 through vn are expressions. A value (a, b) has type (A,B) if a has type A and b has type B. The expression (a) is the same as the expression a. The nullary tuple () (pronounced "unit") is of the trivial type (). See tuple types for details on these types and more ways of constructing tuples.
  • termLink or typeLink literal takes the form termLink aUnisonTerm or typeLink Optional where the argument to termLink is a Unison term and the argument to typeLink is a Unison type. termLink produces a value of type Link.Term and typeLink produces a value of type Link.Type