Skip to content

Important Notice:

This is a Working Draft of the DATEX Specification. This is document is work in progress and may change at any time. It is not intended to be used for production purposes.

10 Type System

10.1 Core Types

DATEX defines a range of core types, from simple primitive types such as integer and text, to more complex composite types such as Map and Set.

The term "core value" refers to a concrete instance of a core type, while "value" is used in a broader sense to denote an instance of any type.

There is no difference between primitive and composite types in their usage. Both can be accessed as references and values.

10.1.1 List of Core Types

10.1.1.1 Non-instantiable Types

TypeDescription
unitThe unit type has a single value, also called unit. It is used as the return type of a function that does not return anything.
neverThe never type has no values. It is used to indicate that a function does not return normally (e.g., it always throws an error).
unknownThe unknown type is the supertype of all types. It can hold any value, but values of this type cannot be used directly.

10.1.1.2 Primitive Types

TypeVariantExample (DATEX Syntax)Description
booleantrue / falseA boolean value can either be true or false.
nullnullA null value.
integer42An integer that can hold arbitrarily large finite positive and negative integer values.
u842u8An integer with a range of 0 to 255.
u1642u16An integer with a range of 0 to 65,535.
u3242u32An integer with a range of 0 to 4,294,967,295.
u6442u64An integer with a range of 0 to 18,446,744,073,709,551,615.
ubig42ubigAn integer with an arbitrary large positive value.
i842i8An integer with a range of -128 to 127.
i1642i16An integer with a range of -32,768 to 32,767.
i3242i32An integer with a range of -2,147,483,648 to 2,147,483,647.
i6442i64An integer with a range of -9,223,372,036,854,775,808 to 9,223,372,036,854,775,807.
ibig42ibigAn integer with an arbitrary large negative or positive value.
decimal42.0A decimal that can hold arbitrarily large finite positive and negative decimal values with arbitrary precision. Additionally, it can hold the special values `infinity`, `-infinity ` and `nan`.
f3242.0f32A 32-bit floating point number.
f6442.0f64A 64-bit floating point number.
big42.0bigA decimal number with arbitrary precision.
amount42mA value consisting of an arbitrary size and precision decimal number and a (composite) SI unit or currency unit
urlhttps://unyt.org/A URL.
endpoint@exampleA DATEX endpoint identifier.
anonymous@@123456789An anonymous DATEX endpoint identifier.
person@userA DATEX endpoint identifier representing a person.
organisation@+unytA DATEX endpoint identifier representing an organisation.
text"Hello DATEX"A string of text.
plain-A string of the text with the mime type text/plain.
markdown-A string of the text with the mime type text/markdown.
html-A string of the text with the mime type text/html.
...-TODO: additional text/* mime types
application-A binary blob with the mime type application/*.
json-A binary blob with the mime type application/json.
pdf-A binary blob with the mime type application/pdf.
...-TODO: additional application/* mime types
audio-An audio file with the mime type audio/*.
mp3-An audio file with the mime type audio/mpeg.
wav-An audio file with the mime type audio/wav.
...-TODO: additional audio/* mime types
video-A video file with the mime type video/*.
mp4-A video file with the mime type video/mp4.
webm-A video file with the mime type video/webm.
...-TODO: additional video/* mime types
image-An image file with the mime type image/*.
png-An image file with the mime type image/png.
jpeg-An image file with the mime type image/jpeg.
svg-An image file with the mime type image/svg+xml.
...-TODO: additional image/* mime types
font-A font file with the mime type font/*.
woff-A font file with the mime type font/woff.
woff2-A font file with the mime type font/woff2.
...-TODO: additional font/* mime types
model-A 3D model file with the mime type model/*.
gltf-A 3D model file with the mime type model/gltf+json.
glb-A 3D model file with the mime type model/gltf-binary.
...-TODO: additional model/* mime types
10.1.1.2.1 Amounts

An amount consists of a decimal number and a unit. The unit can either be a SI unit or a currency unit.

SI Base Units
UnitDescriptionExample DATEX ValueDATEX Type
mmeter42mamount/m
kgkilogram42kgamount/kg
ssecond42samount/s
Aampere42Aamount/A
Kkelvin42Kamount/K
molmole42molamount/mol
cdcandela42cdamount/cd
Currency Units
UnitDescriptionExample DATEX ValueDATEX Type
EUREuro42EURamount/EUR
USDUS Dollar42USDamount/USD
GBPBritish Pound42GBPamount/GBP
JPYJapanese Yen42JPYamount/JPY
CHFSwiss Franc42CHFamount/CHF
............

10.1.1.3 Composite Types

TypeExample (DATEX Syntax)Description
List(1,2,3)A list of arbitrary values.
Array[1,2,3]An array of arbitrary values with a fixed length.
Map("key": "value", (1): 2)A map of arbitrary key-value pairs.
Struct{name: "Alice", age: 30}A struct with fixed named fields containing arbitrary values.
SetSet(1,2,3)A set of unique arbitrary values.
Functionfunction (x: integer) -> integer ( x * 2 ).A pure function that returns the same output value for the same input value, without side effects.
Procedureprocedure (x: integer) -> integer ( x * 2 )A procedure that can have side effects and does not guarantee the same output for the same input.
.........

DATEX Script example (TODO move)

datex
const a = 10; // inferred type for x is 'integer'
const b: integer/i8 = 255; // explicitly specifying type as signed 8-bit integer
const c: text/markdown = "# Markdown content";
const d = (1,2,3); // inferred type is List<integer>
const d: List<integer/i8> = (1,2,3); // Explicitly create a List containing only signed 8-bit integers
const s1 = Set (1,2,3); // creating a new value of type Set<integer> (inferred)
const s3 = Set<integer|text>(1,2,3); // creating a Set with an explicit type

Core types are available on every endpoint instance. Custom type definitions can be loaded as pointers from other endpoints.

10.2 Nominal and Structural Types

The DATEX type system provides both nominal and structural typing.

10.2.1 Type Aliases

10.3 Interfaces

Interfaces are special types that cannot be instantiated. They can contain overridable and sealed properties.

10.4 The ValueConsumer interface

The ValueConsumer<I,O> interface has a single property called handleValue. This property has to be assigned to a Function<I,O>. The function takes a value of type I as input and returns a value of type O.

10.5 The Function interface

The Function<I,O> interface implements the ValueConsumer<I,O> interface.

10.6 The SyncConsumer interface

10.7 The Instantiator interface

The Instantiator interface extends the ValueConsumer interface

10.8 The StreamConsumer interface