> For the complete Mojo documentation index, see [llms.txt](/llms.txt).
> Markdown versions of all pages are available by appending .md to any URL (e.g. /docs/manual/basics.md).

# Mojo types reference

Mojo is statically typed. Every value has a type known at compile time. The
type system is designed to be simple and consistent, with a small set of
core types that can be composed in powerful ways.

## Numbers

Explore numbers on their dedicated page:
[Mojo numeric types](/docs/reference/numeric-types/).

<!-- markdownlint-disable MD013 -->

| Type                                                                            | What it is                                                      |
|---------------------------------------------------------------------------------|-----------------------------------------------------------------|
| [`IntLiteral`](/docs/reference/numeric-types/#int-literal)                      | Arbitrary-precision integer. Compile-time only.                 |
| [`FloatLiteral`](/docs/reference/numeric-types/#float-literal)                  | Arbitrary-precision float. Compile-time only.                   |
| [`Int`](/docs/reference/numeric-types/#int)                                     | Signed integer, system word size. Its own struct.               |
| [`SIMD`](/docs/reference/numeric-types/#simd)                                   | Fixed-size vector of numeric values. Mojo's numeric foundation. |
| [`DType`](/docs/reference/numeric-types/#dtype)                                 | Enumeration of numeric type identifiers. Used as a parameter.   |
| [`Scalar`](/docs/reference/numeric-types/#scalar)                               | Single numeric value. Alias for `SIMD[dtype, 1]`.               |
| [`UInt`](/docs/reference/numeric-types/#uint)                                   | Unsigned integer, system word size. A `Scalar` alias.           |
| [`Int8`-`Int256`](/docs/reference/numeric-types/#sized-integer-types)           | Fixed-width signed integers. `Scalar` aliases.                  |
| [`UInt8`-`UInt256`, `Byte`](/docs/reference/numeric-types/#sized-integer-types) | Fixed-width unsigned integers. `Scalar` aliases.                |
| [`Float16`-`Float64`](/docs/reference/numeric-types/#floating-point-types)      | IEEE 754 floating-point types. `Scalar` aliases.                |
| [`BFloat16`](/docs/reference/numeric-types/#bfloat16)                           | Brain floating-point (16-bit). A `Scalar` alias.                |
| [`Float8_*`, `Float4_*`](/docs/reference/numeric-types/#floating-point-types)   | AI-optimized low-precision floats. `Scalar` aliases.            |

<!-- markdownlint-enable MD013 -->

## Strings

<!-- markdownlint-disable MD013 -->

| Type                 | What it is                                                 |
|----------------------|------------------------------------------------------------|
| [`String`](#strings) | Heap-allocated, owned, mutable UTF-8 string.               |
| `StringSlice`        | Non-owning view into UTF-8 string data.                    |
| `StaticString`       | Immutable slice of static string data. No heap allocation. |
| `StringLiteral`      | Compile-time string constant.                              |

<!-- markdownlint-enable MD013 -->

## Collections

<!-- markdownlint-disable MD013 -->

| Type       | What it is                                |
|------------|-------------------------------------------|
| `Tuple`    | Fixed-size, heterogeneous collection.     |
| `List`     | Dynamically-sized, homogeneous sequence.  |
| `Dict`     | Key-value mapping.                        |
| `Set`      | Unordered collection of unique values.    |
| `Optional` | A value that may or may not be present.   |
| `Variant`  | A value that can be one of several types. |

<!-- markdownlint-enable MD013 -->

## Others

<!-- markdownlint-disable MD013 -->

| Type              | What it is                                   |
|-------------------|----------------------------------------------|
| [`Bool`](#bool)   | Boolean value. Its own struct.               |
| [`Error`](#error) | Represents a runtime error.                  |
| [`Never`](#never) | Return type for functions that don't return. |
| [`None`](#none)   | The type with a single value, `None`.        |

<!-- markdownlint-enable MD013 -->

## `Bool`

`Bool` represents a boolean value (`True` or `False`). It's its own
struct, backed by a 1-bit type, not a SIMD alias.

```mojo
var flag = True
if flag:
    print("yes")
```

## Using strings

Mojo has several string types for different ownership and lifetime
needs.

String literals in source code (like `"hello"`) are `StringLiteral`
values. They implicitly convert to `String` when needed.

All string types use UTF-8 encoding.

Mojo strings are Unicode-aware. Byte length, codepoint count, and
grapheme count are distinct measurements:

```mojo
var s: StringSlice = "café"  # NFD: e + U+0301
print(s.byte_length())       # 5
print(len(s.codepoints()))   # 4
print(s.count_graphemes())   # 4
```

NFD normalization and emoji with modifiers or ZWJ sequences can
widen these gaps further.

## Tuples

A tuple is a fixed-size, heterogeneous collection. Elements can have
different types, and the types are known at compile time.

```mojo
var pair = (42, "hello")
var x = pair[0]  # 42
var y = pair[1]  # "hello"
```

Tuples support unpacking:

```mojo
var a: Int
var b: String
(a, b) = (42, "hello")
```

## `Error`

`Error` represents a recoverable runtime error. Functions that can
fail are marked `raises` and throw `Error` values:

```mojo
def parse(s: String) raises -> Int:
    ...
    raise Error("invalid input")
```

## `Never`

`Never` is the return type for functions that never return, such as
functions that always abort or loop forever:

```mojo
def fatal(msg: String) -> Never:
    print(msg)
    abort()
```

The compiler uses `Never` to prove that code after a call to such a
function is unreachable.

## `None`

`None` is both a value and a type. The `NoneType` struct has exactly
one value: `None`. Functions that don't declare a return type
implicitly return `None`.

```mojo
def greet(name: String):
    print("hello", name)
    # implicitly returns None
```
