Below are FunC types and definitions.

Atomic types

Atomic types synchronize memory access to multiple objects. The following types occupy a single entry in the Total Virtual Memory (TVM) stack.

Type Definition
int A 257-bit signed integer. By default, overflow checks are enabled and lead to an integer overflow exception.
cell Each cell contains up to 1023 bits of data and 4 references to other cells to define the TVM).
slice A fragment of one cell. A slice supports data transfer to other cell slices.
builder A cell builder. Data bits and references to other cells are stored in a builder.
tuple An ordered collection up to 255 components with arbitrary value types in TVM.
cont A continuation controls the flow of TVM program execution.

FunC booleans types

Say goodbye to traditional boolean types. Instead, FunC booleans are represented as integers.

Null value types

FunC Null value types represent the absence of a value of an atomic type. By default, null values are prohibited and lead to a run-time exception.


Hole types

A hole type is a placeholder to be filled with a new type during type checking. _ and var types represent hole types.

Hole type example:

Composite types

Below are FunC composite types.

Type Definition
Functional Functional types take the form A -> B with specified domain and codomain. Example: int -> cell is the functions of one integer argument returning a TVM cell. Internal values are represented as continuations.
Tensor Tensor types represent ordered collections of values of types A, B, etc. When combined, they occupy more than one TVM stack entry.

Tensor examples

Example Description
int -> cell int -> cell is one integer argument and returns a TVM cell. Internal values are represented as continuations.
foo foo has the type int -> (int, int). The function takes one integer and returns a pair of integers. A foo call function looks like (int a, int b) = foo(42);. The internal function consumes one stack entry and leaves two of them.
(2, (3, 9)) (2, (3, 9)) of type (int, (int, int)) and value (2, 3, 9) of type (int, int, int) are the same as three stack entries: 2, 3 and 9. Beware: (int a, int b, int c) = (2, (3, 9)); doesn’t compile properly.
unit type () A unit type is represented as (). It has no value or arguments. Example: the function print_int has the type int -> (). Example: the function random has the type () -> int.
(A) The type form (A) is translated by the type checker as A.

Tuple types

A tuple is a list of types. Tuples combine multiple data elements into a lightweight data structure. Below is an example of a tuple:

let tuple1: [number] = [1];
let tuple2: [number, boolean] = [1, true];
let tuple3: [number, boolean, string] = [1, true, "three"];

Tuple examples:

Type Description
[A, B, ...] Represents one TVM tuple.
[int, cell] A TVM tuple with a length of 2.
[] An empty tuple. The value of [] occupies 1 stack entry.

Polymorphism & type variables

FunC is hardwired with a Miller-Rabin type system used to support polymorphic functions. A polymorphic function takes a single stack entry value and returns two copies of the value.

Polymorphism examples:

In the code example below, X is a type variable.

forall X -> (X, X) duplicate(X value) {
 return (value, value);

Learn more about FunC Polymorphism.

User-defined types

FunC user-defined types are limited to constructions.

Type width

docs by pdgseo.com