Unison identifiers come in two flavors:
- Regular identifiers start with an alphabetic unicode character, emoji (which is any unicode character between 1F400 and 1FAFF inclusive), or underscore (''_''), followed by any number of alphanumeric characters, emoji, or the characters
_
,!
, or\
'. For example,foo
,_bar4
,qux
', andset!
are valid regular identifiers. - Operators consist entirely of the characters
!$%^&*-=+<>~\\/|:
. For example,+
,*
,<>
, and>>=
are valid operators.
Namespace-qualified identifiers
The general reference for identifiers describes unqualified identifiers. An identifier can also be qualified. A qualified identifier consists of a qualifier or namespace, followed by a .
, followed by either a regular identifier or an operator. The qualifier is one or more regular identifiers separated by .
For example Foo.Bar.baz
is a qualified identifier where Foo.Bar
is the qualifier.
The qualifier is one or more regular
Absolutely qualified identifiers
Note that absolutely qualified identifiers are much less prevalent with the advent of Unison projects. They refer to a term from the root of the entire codebase, not the root of a particular project, so their usage is limited to legacy support of a pre-project era.
Namespace-qualified identifiers are relative to a “current” namespace, which the programmer can set (and defaults to the root of the current project). To ignore the current namespace, an identifier can have an absolute qualifier. An absolutely qualified name begins with a .
. For example, the name .base.List
always refers to the name .base.List
, regardless of the current project or namespace, whereas the name base.List
will refer to lib.base.List
if the current namespace contains the base
library in its lib
namespace.
Hash-qualified identifiers
Any identifier, including a namespace-qualified one, can appear hash-qualified. A hash-qualified identifier has the form x#h
where x
is an identifier and #h
is a hash literal. The hash disambiguates names that may refer to more than one thing.
Reserved words
The following names are reserved by Unison and cannot be used as identifiers: =
, :
, ->
, '
, do
, |
, !
, `
, if
, then
, else
, forall
, handle
, unique
, structural
, where
, use
, &&
, ||
, true
, false
, type
, ability
, alias
, let
, namespace
, cases
, match
, with
, termLink
, typeLink
.
Reserved word | Usage context | Example |
= | Used in defining expressions | foo = 42 |
: | Used in type signatures to introduce the type of a term | Nat.increment : Nat -> Nat |
-> | Represents a function in type signatures and lambdas | Nat.isEven : Nat -> Boolean |
' do | Introduces a delayed computation block | main = do printLine "hi!" |
| | Used in pattern matching and guards and in separating type constructors | match n with n | Nat.isEven n -> "even" |
! | Used to force a delayed computation | !console.readLine |
` | Used in documentation to indicate a code snippet or example | {{`anExample = "in a doc"`}} |
if then else | Used in conditional expressions | if x > 0 then "positive" else "negative" |
forall | Used in polymorphic type signatures | forall a. a -> a |
handle | Used in ability handlers | handle resume() with h (acc ++ [e]) |
unique | Introduces a unique type in a type definition | unique type MyType = MyType Nat |
structural | Introduces a structural type in a type definition | structural type ConsList a = Cons a | Nil |
where | Introduces the request constructors for an ability |
|
use | Imports a term or type into the current scope | use Nat + |
&& | Logical AND operator | true && false |
|| | Logical OR operator | true || false |
true false | Boolean literals | true false |
type | Introduces a new type definition |
|
ability | Introduces a new ability definition | ability Console where ... |
alias | Introduces an alias for a term or type | |
let | Introduces a new indended codeblock inside a definition |
|
namespace | In a file, specifies that the subsequent definitions should be prefixed with the given namespace | namespace myNamespace |
cases | Alternative syntax for pattern matching | cases foo -> "bar" |
match with | Pattern matching syntax | match foo with |
typeLink | Creates a link to a type definition, used primarily in creating Failure s for exceptions | Failure (typeLink Generic) msg (Any a) |
termLink | Creates a link to a term definition |