Skip to content

Data Types

AndcoolSystems edited this page Jun 19, 2026 · 3 revisions

Data Types

Ultraviolet provides a set of built-in data types, including numbers, strings, boolean values, functions, and special utility types.

Because Ultraviolet is a statically and strongly typed language, every value has a well-defined type that is verified during type checking.

Built-in Types

Numeric Types

Signed Integers

  • <i8 />
  • <i16 />
  • <i32 />
  • <i64 />

Unsigned Integers

  • <u8 />
  • <u16 />
  • <u32 />
  • <u64 />

Floating-Point Numbers

  • <f32 />
  • <f64 />

Boolean Type

  • <bool />

Boolean values may only contain 0 | 1 or false | true.

String Type

  • <str />

Function Type

See the Functions section for more information.

  • <fn>...</fn>

Special Types

  • <null /> — represents a null value. This type may be removed in future versions of the language.
  • <void /> — represents the absence of a value.

Creating Values

A value instance is created by placing a valid value inside the corresponding type tag.

Example

<u8>5</u8>

This creates a value of type u8 with the value 5.

Attempting to create a value that does not match the target type will result in a type-checking error.

Examples

<i32>-100</i32>

<f64>3.1415926535</f64>

<bool>1</bool>

<str>Hello World!</str>

Invalid Examples

<u8>-5</u8>

<i32>Hello</i32>

All of the examples above will produce type-checking errors.

String Labels

The str type supports labels, which allow string literals to safely contain text that would otherwise be interpreted as Ultraviolet syntax.

A label is specified after the tag name using the following format:

<str-my_label>
    ...
</str-my_label>

The interpreter will only treat a closing tag with the same label as the end of the string.

Example

<str-random_label>
This string contains <str> as plain text!
</str-random_label>

In this case, the inner <str> sequence becomes part of the string value rather than being parsed as a nested tag.

Why Labels Exist

Labels are useful when storing:

  • Source code
  • XML fragments
  • Templates
  • Documentation
  • Any text that may contain Ultraviolet tags

Without labels, such content could prematurely terminate the string.

Special Types

Unlike primitive value types, special types do not accept content.

Valid

<null />

<void />

Invalid

<null>value</null>

<void>value</void>

These forms are not allowed.

Using Types as Type Declarations

Types can be used not only to create values, but also to explicitly declare types.

Whenever the interpreter expects a type declaration, the type must be provided as a self-closing tag.

Example

<let>
    <name>...</name>

    <type>
        <i32 />
    </type>

    <value>
        ...
    </value>
</let>

In this context, <i32 /> describes a type rather than a value.

Note

Type declarations never contain values.

Reference Types

See the References section for more information.

Any type can be marked as a reference type by adding the ref modifier.

Example

<str ref />
<i32 ref />
<f64 ref />

A reference type stores a reference to a value instead of the value itself.

Reference types are commonly used when passing mutable data between functions or when working directly with memory references.