Clarity Smart Contract Language


Clarity of Mind Foreword Introduction


(If you are looking for type signatures, see the later chapter on variables.)

An important concept for many programming languages are the so-called types. A type defines what kind of information can be stored inside a variable. If you imagine a variable to be a container that can hold something, the type defines what kind of thing it holds.

Types are strictly enforced and cannot mix in Clarity. Type safety is key because type errors (mixing two different types) can lead to unexpected errors with grave consequences. Clarity therefore rejects any kind of type mixing. Here is an example:

(+ 2 u3)

The expression above results in an error:

Analysis error: expecting expression of type 'int', found 'uint' (+ 2 u3)

Before we can properly answer the question of which type it was expecting where, let us take a look at the different types in Clarity. Types fall in three categories: primitives, sequences, and composites.

  • Primitives are the basic building blocks for the language. They include numbers and boolean values (true and false).
  • Sequences hold multiple values in order.
  • Composites are complex types that are made up of other types.