Below are FunC types and definitions.
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. |
Say goodbye to traditional boolean types. Instead, FunC booleans are represented as integers.
false
= 0
true
= -1
true
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.
Example:
A
is transformed into type A^?
(a.k.a. Maybe A
).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:
var x = 2;
is a definition of variable x
equal to 2
. The type checker infers that x
has the type int
because 2
has type int
. The left and right sides of an assignment must have equal 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. |
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 . |
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. |
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:
duplicate(6)
has a value of 6 6
.duplicate([])
creates two copies [] []
of an empty tuple.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.
FunC user-defined types are limited to constructions.
docs by pdgseo.com