A literal expression is a basic form of Unison expression. Unison has the following types of literals:
- A64-bit unsigned integerof type
Nat
(which stands fornatural number)consists of digits from 0 to 9. The smallestNat
is0
and the largest is18446744073709551615
. - A64-bit signed integerof type
Int
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
. - A64-bit floating point numberof type
Float
consists of an optional sign (''+''/''-''), followed by two natural numbers separated by.
.Floating point literals in Unison areIEEE 754-1985double-precision numbers. For example1.6777216
is a valid floating point literal. - Atext literalof 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"
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 type
Char
consists of a?
character marker followed by a single Unicode character, or a singleescape sequence.For example,?a
,?🔥
or?\t
. - There are twoBoolean literals:
true
andfalse
,and they have typeBoolean
. - Abyte literalstarts with
0xs
.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.#a0v829
is an example of a hash literal. - Aliteral listhas 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]
. - Afunction literalor lambda has the form
p1 p2 … pn -> e
,wherep1
throughpn
areregular identifiersande
is a Unison expression (thebodyof 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 sectionFunction Applicationfor details on call semantics). For examplex -> x Nat.+ 2
is a function literal. - Atuple literalhas 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 tuplesuperProgram : Boolean -> Nat superProgram bool = if Boolean.not bool then base.bug (Generic.failure "Fatal Issue Encountered" bool) else 100
(pronounced “unit”) is of the trivial type()
.Seetuple typesfor 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 typeType