Skip to main content

Maybe

nothing$0 {X:Type} = Maybe X;
just$1 {X:Type} value:X = Maybe X;
The Maybe combinator is used to represent optional values. In this case, the first bit indicates a value. If the bit is 0, the value is not serialized and skipped. If the bit is 1, the value follows and is serialized.

Either

left$0 {X:Type} {Y:Type} value:X = Either X Y;
right$1 {X:Type} {Y:Type} value:Y = Either X Y;
The Either type is used when one of two possible result types may be present. The choice of type depends on the prefix bit. If the prefix bit is 0, then the left type is serialized. If it is 1, the right type is serialized. This construct is used, for example, when serializing messages: where the body is either included directly in the main cell or stored in a separate referenced cell.

Both

pair$_ {X:Type} {Y:Type} first:X second:Y = Both X Y;
The Both type variation is used exclusively with regular pairs, where both types are serialized sequentially without any conditions.

VarUInteger n

var_uint$_ {n:#} len:(#< n) value:(uint (len * 8)) = VarUInteger n;
The combinator is parameterized by a natural number n, represented in curly brackets. For a given n, VarUInteger n describes the serialization of a natural number m, which in its binary representation contains no more than n * 8 bits. First, the number of bytes required for writing m, that is called len, is serialized into log2n\lceil \log_{2}n \rceil bits as an unsigned big-endian integer. Then m itself is serialized as a uint on len*8 bits. Thus, the size of the serialization of a particular m through the combinator VarUInteger n depends on m. This type is used as the representation of an amount of toncoins stored on the account.
I