Literals

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

  • A64-bit unsigned integerof typeNat(which stands fornatural number)consists of digits from 0 to 9. The smallestNatis0and the largest is18446744073709551615.
  • A64-bit signed integerof typeIntconsists of a natural number immediately preceded by either+or-.For example,4is aNat,whereas+4is anInt.The smallestIntis-9223372036854775808and the largest is+9223372036854775807.
  • A64-bit floating point numberof typeFloatconsists of an optional sign (''+''/''-''), followed by two natural numbers separated by..Floating point literals in Unison areIEEE 754-1985double-precision numbers. For example1.6777216is a valid floating point literal.
  • Atext literalof typeTextis any sequence of Unicode characters between pairs of".The escape character is\,so a"can be included in a text literal with the escape sequence\".The full list of escape sequences is given in theEscape Sequencessection 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.
  • Acharacter literalof typeCharconsists of a?character marker followed by a single Unicode character, or a singleescape sequence.For example,?a,?🔥or?\t.
  • There are twoBoolean literals:trueandfalse,and they have typeBoolean.
  • Abyte literalstarts with0xs.For example0xsdeadbeef
  • Ahash literalbegins with the character#.See the sectionHashesfor 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.#a0v829is an example of a hash literal.
  • Aliteral listhas the general form[v1, v2, … vn]wherev1throughvnare 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 isT,then the type of the list literal is.base.List Tor[T].
  • Afunction literalorlambdahas the formp1 p2 … pn -> e,wherep1throughpnareregular identifiersandeis a Unison expression (thebodyof the lambda). The variablesp1throughpnare local variables ine,and they are bound to any values passed as arguments to the function when it’s called (see the sectionFunction Applicationfor details on call semantics). For examplex -> x Nat.+ 2is a function literal.
  • Atuple literalhas the form(v1,v2, …, vn)wherev1throughvnare expressions. A value(a, b)has type(A,B)ifahas typeAandbhas typeB.The expression(a)is the same as the expressiona.The nullary tuple()(pronounced “unit”) is of the trivial type().Seetuple typesfor details on these types and more ways of constructing tuples.
  • termLinkortypeLinkliteral takes the formtermLink aUnisonTermortypeLink Optionalwhere the argument totermLinkis a Unison term and the argument totypeLinkis a Unison type.termLinkproduces a value of typeLink.Termand typeLink produces a value of typeType