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 smallestNat
is0
and the largest is18446744073709551615
. * You can also writeNat
numbers in their hex format0x
, as in0x003
for3
. * A__64-bit signed integer of typeInt
consists of a natural number immediately preceded by either+
or-
. For example,4
is aNat
, whereas+4
is anInt
. The smallestInt
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 example1.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
andfalse
, and they have typeBoolean
. * A__byte literal starts with0xs
. For example0xsdeadbeef
- 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]
wherev1
throughvn
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 isT
, 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
, wherep1
throughpn
are regular identifiers ande
is a Unison expression (the body of the lambda). The variablesp1
throughpn
are local variables ine
, 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 examplex -> x Nat.+ 2
is a function literal. - A tuple literal has the form
(v1,v2, ā¦, vn)
wherev1
throughvn
are expressions. A value(a, b)
has type(A,B)
ifa
has typeA
andb
has typeB
. The expression(a)
is the same as the expressiona
. 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
ortypeLink
literal takes the formtermLink aUnisonTerm
ortypeLink Optional
where the argument totermLink
is a Unison term and the argument totypeLink
is a Unison type.termLink
produces a value of typeLink.Term
and typeLink produces a value of typeLink.Type