Data type algebra

Fundamental types

Fundamental types are types built-in in strict encoding and not derived from any other types. These types include:

  1. Unit type ()

  2. Byte type Byte

  3. Integer numbers (signed I_, unsigned U_ and natural N_)

  4. Floating-point numbers F_

  5. UTF-8 character Utf8

Byte type is introduced due to the fact that it semantically different from a 8-bit signed or unsigned integer: it does not contain information about sign and may not be representative with an integer at all.

While Unicode character type can be expressed expressed as a composite type, it will be very verbose expression (union with 256 variants), so for the practical purposes (to reduce the complexity of types which use Unicode strings) it was decided to built it in.

Strict encoding has reserved place for 55 more types, which may be introduced in a future to represent more floating-point integer encodings, Unicode variants etc. At the present moment use of that type identifiers would result in encoding/decoding failure.

Integers

Integer types are named using a single upper case latter specifying set of integers used in type (U for unsigned, I for signed and N for natural non-zero integers) followed by a decimal number of bits in the type encoding (like U8 or I1024).

Strict encoding covers integer types of different size in two ranges:

In total, there are 64 different types for unsigned integers, 64 types for signed and 64 types for non-zero integers, giving 194 possible integer types in total. Not all of these types have a representation in all of the supported languages, so below we give a list of integer types which can be represented in Rust:

Floating-point numbers

Strict encoding supports the following floating number encodings:

Strict encoding has 54 more type identifiers reserved for possible use by future floating-point number encodings (like Tappered float etc); at the present moment use of that type identifiers would result in encoding/decoding failure.

Type composition

Strict encoding uses generalized algebraic data types (GADT). This means that new types can be composed out of primitive types via following fundamental morphisms:

Enums

Enums are a special case of unit type in which each variant is represented by a Byte value.

Dynamic collections

Fundamental morphisms can be used to build more advanced types, like dynamic maps and dynamic arrays of tuples

For simplifying syntax strict encoding provides comprehensions and defaults for specifying the confinement bounds:

Please note that type expression of [•^N..N]is not allowed, since it means "dynamic" collection with a fixed number of items, which is nonsense, so please use [•^N] instead.

Optionals

A special case of union type of frequent use is an optional monad, which may contain some type or be None. In strict encoding there is a special comprehension for writing an optional: T?, which is an equivalend ot writing (()|T).

Types provided by the standard library

Most frequently used types are provided by a strict encoding standard library StdLib:

Last updated