Introduction
Prospero is a configuration language designed to help you generate static resources such as JSON and YAML easily, safely and reliably. To this end, Prospero is statically typed and has powerful type inference so that you can write complex configurations with minimal boilerplate but retain robust guarantees about type safety.
Prospero also provides strong runtime guarantees, ensuring that all programs terminate by allowing only structural recursion. Configuration that loops forever is one of the dangers of using more traditional programming languages in this problem space: Prospero prevents the problem by design.
Prospero has the following features:
- Parametric polymorphism (including higher-kinded types)
- Structural Records
- Algebraic Data Types (ADTs)
- Pattern matching
- Type Classes
- Rank-N types
- Units of Measure
- Structural recursion
Getting Started
Installation
With Nix
-
Install Nix the package manager.
-
Ensure Nix Flakes are enabled. If you just installed Nix you can do:
mkdir -p ~/.config/nix echo "experimental-features = nix-command flakes" >> ~/.config/nix/nix.conf -
Create a
flake.nixfile with the contents described below. -
Run
nix develop. -
Run
prospero helpto confirm your development environment is working correctly.
flake.nix
{
description = "My prospero project";
inputs = {
prospero.url = "git+https://codeberg.org/theinnerlight/prospero.git";
nixpkgs.follows = "prospero/nixpkgs";
flake-utils.follows = "prospero/flake-utils";
};
outputs = { nixpkgs, flake-utils, prospero, ... }:
flake-utils.lib.eachDefaultSystem (system:
let
pkgs = nixpkgs.legacyPackages.${system};
prosperoPackage = prospero.packages.${system}.default;
in
{
packages.default = prosperoPackage;
devShells.default = pkgs.mkShell {
packages = [ prosperoPackage ];
};
});
}
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:
Builtin types
These types are provided by the compiler.
Bool
Bytes
DateTime
Instances
Decimal<'m>
Instances
instance Eq Decimal<'m>instance Ord Decimal<'m>instance Num Decimalinstance Real Decimalinstance ToString Decimal<'m>instance ToStringFormat Decimal<'m> Precisioninstance ToStringFormat Decimal<'m> PrecisionWithoutUnitinstance ToStringFormat Decimal<'m> WithoutUnitinstance ToJson Decimal<1>
Integer<'m>
Instances
String
Instances
Prelude
The Prelude is automatically imported unqualified into every other Prospero module. It provides the core functionality of the language.
Types
data List a
= Nil
| Cons { head : a, tail : List a }
Instances
data Precision
= Precision (Int)
Instances
instance ToStringFormat Decimal<'m> Precision
data WithoutUnit
= WithoutUnit
Instances
instance ToStringFormat Decimal<'m> WithoutUnitinstance ToStringFormat Integer<'m> WithoutUnit
data PrecisionWithoutUnit
= PrecisionWithoutUnit (Int)
Instances
instance ToStringFormat Decimal<'m> PrecisionWithoutUnit
data Option a
= None
| Some (a)
Instances
data Json
= JNull
| JBool Bool
| JNumber (Decimal<1>)
| JString String
| JArray (List Json)
| JObject (List { key : String, value : Json })
Classes
class Eq a where
class Eq a => Ord a where
order : a -> a -> Int
Returns the order that two values appear in. It returns -1 if the first value is lower than the second; 0 if they are the same; and +1 if the first value is greater than the second.
Instances
class Num a where
add : a<'m> -> a<'m> -> a<'m>
Addition
subtract : a<'m> -> a<'m> -> a<'m>
Subtraction
multiply : a<'m> -> a<'n> -> a<'m 'n>
Multiplication
fromInteger : Int -> a<1>
Conversion from an Int.
zero : a<'m>
The value zero.
Instances
class Num a => Real a where
divide : a<'m> -> a<'n> -> a<'m / 'n>
Division
sqrt : a<'m^2> -> a<'m>
Square root
floor : a<'m> -> Integer<'m>
Returns the largest Integer that is less than or equal to the supplied value.
pow : a<1> -> a<1> -> a<1>
Raise to the power of
exp : a<1> -> a<1>
Returns e raised to the supplied power.
ln : a<1> -> a<1>
Returns the natural logarithm of the supplied value.
log10 : a<1> -> a<1>
Returns the base 10 logarithm of the supplied value.
pi : a<1>
Returns the value of pi.
Instances
class Functor f where
map : (a -> b) -> f a -> f b
Returns the result of applying a function of type a -> b and a value of type f a to produce a value of type f b.
Instances
class Functor f => Applicative f where
pure : a -> f a
Lifts a supplied value into the structure.
apply : f (a -> b) -> f a -> f b
Sequential application
Instances
instance Applicative Listinstance Applicative Option
class ToString a where
class Semigroup a where
sappend : a -> a -> a
An associative binary operation.
Instances
class Semigroup a => Monoid a where
class Foldable t where
foldr : (a -> b -> b) -> b -> t a -> b
Right associative fold of a collection.
foldl : (b -> a -> b) -> b -> t a -> b
Left associative fold of a collection.
Instances
class (Functor t, Foldable t) => Traversable t where
traverse : forall f a b. Applicative f => (a -> f b) -> t a -> f (t b)
Map each element of a structure to an action, evaluate these actions from left to right and collect the results.
Instances
instance Traversable Listinstance Traversable Optioninstance Traversable (Map k)instance Traversable (Tree k)
class ToStringFormat a f where
toStringF : f -> a -> String
Instances
instance ToStringFormat Decimal<'m> Precisioninstance ToStringFormat Decimal<'m> PrecisionWithoutUnitinstance ToStringFormat Decimal<'m> WithoutUnitinstance ToStringFormat Integer<'m> WithoutUnit
class ToJson a where
Functions
compose : forall a b c. (b -> c) -> (a -> b) -> a -> c
Function composition of two supplied functions f and g.
flip : forall a b c. (a -> b -> c) -> b -> a -> c
Applies a function f to its first two arguments in reverse order.
identity : forall a. a -> a
The identity function.
concatMap : forall t a b. Foldable t => (a -> List b) -> t a -> List b
Returns the result of concatenating the applications of f to each element of a collection xs.
fold : forall t m. (Foldable t, Monoid m) => t m -> m
Returns the result of combining the elements of a supplied collection xs, whose elements are Monoids, using Semigroup’s sappend function.
sum : forall t n 'm. (Foldable t, Num n) => t (n<'m>) -> n<'m>
Returns the sum of the elements of a supplied collection xs.
product : forall t n. (Foldable t, Num n) => t (n<1>) -> n<1>
Returns the product of the elements of a supplied collection xs.
head : forall t a. Foldable t => t a -> Option a
Returns the first element of a supplied collection xs if it exists.
any : forall t a. Foldable t => (a -> Bool) -> t a -> Bool
Returns whether any element of the supplied collection xs satisfies the predicate p.
all : forall t a. Foldable t => (a -> Bool) -> t a -> Bool
Returns whether all elements of the supplied collection xs satisfy the predicate p.
find : forall t a. Foldable t => (a -> Bool) -> t a -> Option a
Returns the left-most element of the supplied collection xs that satisfies the predicate p.
maximum : forall t a. (Foldable t, Ord a) => t a -> Option a
Returns the largest element of the supplied collection xs if it exists.
minimum : forall t a. (Foldable t, Ord a) => t a -> Option a
Returns the smallest element of the supplied collection xs if it exists.
length : forall t a. Foldable t => t a -> Int
Returns the length of the supplied collection xs.
mean : forall t n 'm. (Foldable t, Real n) => t (n<'m>) -> Option (n<'m>)
Returns the mean value of the elements of the supplied collection xs when possible.
sort : forall a. Ord a => List a -> List a
Returns the elements of the supplied List xs ordered from lowest to highest, keeping duplicates in the order they appeared in the input.
groupBy : forall t a b. (Foldable t, Eq b) => (a -> b) -> t a -> List { key : b, values : List a }
Returns the result of partitioning the supplied collection xs by some discriminating function f.
median : forall t n 'm. (Foldable t, Real n, Ord (n<'m>)) => t (n<'m>) -> Option (n<'m>)
Returns the median value of the elements of the supplied collection xs when possible.
sequence : forall f t a. (Applicative f, Traversable t) => t (f a) -> f (t a)
Evaluate each action in the collection from left to right and collect the results.
divMod : forall 'm. Integer<'m> -> Integer<'m> -> { quot : Int, rem : Integer<'m> }
Returns the result of the Integer division and remainder of two values with the quotient rounded toward negative infinity.
Prospero.Bytes
Functions on sequences of Bytes.
Functions
base64Encode : Bytes -> String
Returns the base64 encoding of a supplied sequence of Bytes.
Prospero.List
Functions on Lists. Many functions that you might expect to find here are provided generically by Foldable in the Prelude module.
Functions
filter : forall a. (a -> Bool) -> List a -> List a
Returns the elements of the supplied list xs that satisfy the supplied predicate p.
range : Int -> Int -> List Int
Returns the integers in the range lo..hi (including both low and high).
replicate : forall a. Int -> a -> List a
Returns a list of length n that contains the supplied value x at every element.
reverse : forall a. List a -> List a
Returns the supplied list xs in reverse order.
singleton : forall a. a -> List a
Returns a list containing a single supplied element x.
Prospero.Map
An efficient implementation of maps from keys to values based on immutable red-black trees.
Types
data Map k v
= Map { tree : Tree k v }
waiving Eq, Ord
Instances
Functions
delete : forall k v. Ord k => k -> Map k v -> Map k v
Returns the result of deleting the supplied key k from the map m.
difference : forall k v w. Ord k => Map k v -> Map k w -> Map k v
Returns the difference of two Maps.
empty : forall k v. Map k v
Returns the empty Map.
fromList : forall k v. Ord k => List { key : k, value : v } -> Map k v
Returns a Map constructed from a list of key value pairs.
insert : forall k v. Ord k => k -> v -> Map k v -> Map k v
Returns the result of inserting a new key k and value v into the Map.
intersection : forall k v w. Ord k => Map k v -> Map k w -> Map k v
Returns the intersection of two Maps.
lookup : forall k v. Ord k => k -> Map k v -> Option v
Returns the value at a supplied key k in the Map if possible.
singleton : forall k v. k -> v -> Map k v
Returns a map with a single supplied element with key k and value v.
size : forall k v. Map k v -> Int
Returns the size of the Map.
toList : forall k v. Map k v -> List { key : k, value : v }
union : forall k v. Ord k => Map k v -> Map k v -> Map k v
Returns the union of two Maps.
Prospero.RBTree.Internal
Types
data Tree k v
= Empty
| Node { colour : Colour, left : Tree k v, key : k, value : v, right : Tree k v }
data Colour
= Red
| Black
Functions
contains : forall k v. Ord k => k -> Tree k v -> Bool
difference : forall k v w. Ord k => Tree k v -> Tree k w -> Tree k v
delete : forall k v. Ord k => k -> Tree k v -> Tree k v
empty : forall k v. Tree k v
fromList : forall k v. Ord k => List { key : k, value : v } -> Tree k v
insert : forall k v. Ord k => k -> v -> Tree k v -> Tree k v
intersection : forall k v w. Ord k => Tree k v -> Tree k w -> Tree k v
lookup : forall k v. Ord k => k -> Tree k v -> Option v
singleton : forall k v. k -> v -> Tree k v
size : forall k v. Tree k v -> Int
toList : forall k v. Tree k v -> List { key : k, value : v }
union : forall k v. Ord k => Tree k v -> Tree k v -> Tree k v
node : forall k v. Colour -> Tree k v -> k -> v -> Tree k v -> Tree k v
makeBlack : forall k v. Tree k v -> Tree k v
height : forall k v. Tree k v -> Int
ins : forall k v. Ord k => k -> v -> Tree k v -> Tree k v
balance : forall k v. Colour -> Tree k v -> k -> v -> Tree k v -> Tree k v
balanceLeft : forall k v. Tree k v -> k -> v -> Tree k v -> Tree k v
balanceRight : forall k v. Tree k v -> k -> v -> Tree k v -> Tree k v
deleteLeft : forall k v. Ord k => k -> Tree k v -> k -> v -> Tree k v -> Tree k v
deleteRight : forall k v. Ord k => k -> Tree k v -> k -> v -> Tree k v -> Tree k v
fuse : forall k v. Tree k v -> Tree k v -> Tree k v
del : forall k v. Ord k => k -> Tree k v -> Tree k v
Prospero.String
Functions on Strings.
Functions
append : String -> String -> String
Returns the result of appending one String to another.
toLowerCase : String -> String
Returns the result of converting a supplied String to lower case.
toUpperCase : String -> String
Returns the result of converting a supplied String to upper case.
utf8Encode : String -> Bytes
Returns the UTF-8 encoding of a supplied String.
Prospero.Units.SI
A list of SI units. The fundamental definitions are SI base units but the module includes a variety of derived units including those with scaling factors.
Measures
| Measure | Definition |
|---|---|
m | base unit |
kg | base unit |
s | base unit |
A | base unit |
K | base unit |
mol | base unit |
cd | base unit |
rad | <1> |
sr | <1> |
Hz | <s^-1> |
N | <kg m s^-2> |
Pa | <N / m^2> |
J | <N m> |
W | <J / s> |
C | <A s> |
V | <W / A> |
F | <C / V> |
Ω | <V / A> |
S | <A / V> |
Wb | <V s> |
T | <Wb / m^2> |
H | <Wb / A> |
lm | <cd sr> |
lx | <lm / m^2> |
Bq | <s^-1> |
Gy | <J / kg> |
Sv | <J / kg> |
kat | <mol / s> |
km | <1000 m> |
cm | <0.01 m> |
mm | <0.001 m> |
μm | <0.001 mm> |
nm | <0.001 μm> |
pm | <0.001 nm> |
fm | <0.001 pm> |
g | <0.001 kg> |
mg | <0.001 g> |
μg | <0.001 mg> |
ng | <0.001 μg> |
pg | <0.001 ng> |
fg | <0.001 pg> |
ms | <0.001 s> |
μs | <0.001 ms> |
ns | <0.001 μs> |
ps | <0.001 ns> |
fs | <0.001 ps> |
kHz | <1000 Hz> |
MHz | <1000 kHz> |
GHz | <1000 MHz> |
THz | <1000 GHz> |
mA | <0.001 A> |
mV | <0.001 V> |
kV | <1000 V> |
kΩ | <1000 Ω> |
MΩ | <1000 kΩ> |
kN | <1000 N> |
kPa | <1000 Pa> |
MPa | <1000 kPa> |
kJ | <1000 J> |
MJ | <1000 kJ> |
GJ | <1000 MJ> |
TJ | <1000 GJ> |
kW | <1000 W> |
MW | <1000 kW> |
GW | <1000 MW> |
TW | <1000 GW> |
mT | <0.001 T> |
μT | <0.001 mT> |
nT | <0.001 μT> |
mF | <0.001 F> |
μF | <0.001 mF> |
nF | <0.001 μF> |
pF | <0.001 nF> |
mC | <0.001 C> |
μC | <0.001 mC> |
nC | <0.001 μC> |
pC | <0.001 nC> |
mSv | <0.001 Sv> |
μSv | <0.001 mSv> |
mmol | <0.001 mol> |
μmol | <0.001 mmol> |
Prospero.Units.SI.Accepted
A list of additional units that are accepted for use with the SI units.