Skip to main content
Version: 0.66.0

Native Types

This page describes the built-in data shapes that are part of the language itself rather than stdlib modules.

Lists

Type form: 'a list

FormSignatureDescription
[]'a listEmpty list literal.
head :: tail'a -> 'a list -> 'a listPrepends one item to a list.
left @ right'a list -> 'a list -> 'a listConcatenates two lists.
values[index]'a list -> int -> 'a optionZero-based optional indexer. Negative or out-of-range indices return None.
let xs = [10; 20; 30]
let maybeSecond = xs[1]

Maps

Type form: 'v map

Map keys are always string.

FormSignatureDescription
{}'v mapEmpty map literal.
{ ["key"] = value }string -> 'v -> 'v mapMap literal entry syntax.
values[key]'v map -> string -> 'v optionOptional key lookup. Missing keys return None.
{ ..tail }'v map -> 'v mapSpread syntax used when building or updating a map.
let scores = { ["math"] = 18; ["english"] = 16 }
let maybeMath = scores["math"]

Options

Type form: 'a option

FormSignatureDescription
Some value'a -> 'a optionWraps a present value.
None'a optionRepresents the absence of a value.

Use pattern matching or Option.* helpers to consume options.

Tuples

Type form: (t1 * t2 * ...)

FormSignatureDescription
(a, b)'a * 'bTuple literal.
let (a, b) = value('a * 'b) -> unitTuple destructuring in bindings.
tuple pattern matching('a * 'b) -> 'rUse match value with (a, b) -> ... to decompose tuples.

Tuples do not have a native indexer. Destructure them instead.

Records

Type form: { Field: t; ... }

FormSignatureDescription
{ Name = value }field-set dependentRecord literal.
record.Field{ Field: 'a; ... } -> 'aField access by name.
{ record with Field = value }same record type -> same record typeRecord update syntax.

Unions

Type form: type Shape = | Point | Circle of int

FormSignatureDescription
Casecase dependentUnion constructor without payload.
Case valuepayload type -> union typeUnion constructor with payload.
union pattern matchingunion type -> 'rUse match value with Case x -> ... to branch on union cases.

Scalars

Primitive built-in types:

  • int
  • float
  • bool
  • string
  • unit

These do not use indexers. For parsing and formatting helpers, see Int, Float, Bool Modules and String Module.