Basic Types
Built-in Types
Prospero provides the following types which are built-in to the language.
| Type | Example | Description |
|---|---|---|
Bool | True | True or False |
Bytes | 0x"ffff" | An arbitrary sequence of raw bytes. |
DateTime | 2026-10-24T14:35:54Z | An ISO 8601 DateTime |
Dec | -17.7 | A base-10 decimal number. Type alias for Decimal<1> |
Decimal<'m> | 2.99792458e8<m s^-1> | A base-10 decimal number with attached unit of measure. |
Int | 97 | A signed integer. Type alias for Integer<1> |
Integer<'m> | 33<s> | A signed integer with attached unit of measure. |
String | "Hello World!" | An arbitrary length unicode string stored in UTF-8. |
Record Types
Records consist of a list of field names and associated values.
An example of a record type is:
{ author : String
, character : String
, play : String
}
An example value of a record of this type is:
{ author = "William Shakespeare"
, character = "Prospero"
, play = "The Tempest"
}
Projection
Record types support projection using .. For example, suppose that I write:
let prospero =
{ author = "William Shakespeare"
, character = "Prospero"
, play = "The Tempest"
}
I can then write
prospero.character
This has the value "Prospero" of type String.
Properties
- Records are purely structural; two records that have the same set of field names with the same field types count as the same type of record.
- A record is equal to another record if its fields contain the same values.
- Records are ordered by the contents of their fields lexicographically, i.e. in the above record it will be sorted first by
author, then bycharacterand finally byplay.
Data Types
It is often much more convenient to work with named data types rather than Records.
Data Records
The simplest data types are called Data Records; they are simply a data declaration wrapped around a record.
data PlayCharacter = PlayCharacter
{ author : String
, character : String
, play : String
}
This is very similar to what we had before but, crucially, it has the type PlayCharacter rather than { author : String, character : String, play : String}. This is very much simpler if you need to refer to the type!
Projection
Data records support projection using . just like regular records. If we modify the previous example:
let prospero = PlayCharacter
{ author = "William Shakespeare"
, character = "Prospero"
, play = "The Tempest"
}
prospero.character
Everything works just like before: it returns the value "Prospero" of type String.
Algebraic Data Types (ADTs)
The other form of data type that Prospero supports are called Algebraic Data Types or ADTs. These are also known variously elsewhere as Sum Types, Discriminated Unions, etc. They encode a series of alternatives.
The simplest form of ADT is similar to an Enum:
data MagicalItem
= Staff
| Book
This defines a data type of type MagicalItem which allows the values Staff or Book.
ADTs also support containing data of their own. For example: