Keyboard shortcuts

Press or to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Built-in types & functions

This page is auto-generated from the prelude source. Run cargo run -p rex --bin gen_prelude_docs to refresh it.

Built-in Types

TypeDescription
Array aFixed-size indexed sequence.
Dict aDictionary/record-like mapping from field labels to values.
List aImmutable singly linked list. Constructors: Empty, Cons.
Option aOptional value (Some or None). Constructors: Some, None.
Result a bResult value (Ok or Err) for success/failure flows. Constructors: Err, Ok.
boolBoolean truth value.
datetimeUTC timestamp value.
f3232-bit floating-point number.
f6464-bit floating-point number.
i1616-bit signed integer.
i3232-bit signed integer.
i6464-bit signed integer.
i88-bit signed integer.
stringUTF-8 string value.
u1616-bit unsigned integer.
u3232-bit unsigned integer.
u6464-bit unsigned integer.
u88-bit unsigned integer.
uuidUUID value.

Built-in Type Classes

AdditiveGroup

Types supporting additive inverse and subtraction.

Superclasses: Semiring

Methods:

  • negate: AdditiveGroup 'a => ('a -> 'a). Additive inverse.
  • -: AdditiveGroup 'a => ('a -> ('a -> 'a)). Subtraction.

AdditiveMonoid

Types with additive identity and associative addition.

Superclasses: none

Methods:

  • zero: AdditiveMonoid 'a => 'a. Additive identity.
  • +: AdditiveMonoid 'a => ('a -> ('a -> 'a)). Addition (or concatenation for strings).

Alternative

Applicative types with a fallback choice operation.

Superclasses: Applicative

Methods:

  • or_else: Alternative 'f => ((('f 'a) -> ('f 'a)) -> (('f 'a) -> ('f 'a))). Provide an alternative container value.

Applicative

Functors that can lift values and apply wrapped functions.

Superclasses: Functor

Methods:

  • pure: Applicative 'f => ('a -> ('f 'a)). Lift a plain value into an applicative context.
  • ap: Applicative 'f => (('f ('a -> 'b)) -> (('f 'a) -> ('f 'b))). Apply wrapped functions to wrapped values.

Default

Types with a canonical default value.

Superclasses: none

Methods:

  • default: Default 'a => 'a. Canonical default value for a type. For Result a e, this requires Default a.

Eq

Types supporting equality/inequality comparison.

Superclasses: none

Methods:

  • ==: Eq 'a => ('a -> ('a -> bool)). Equality comparison.
  • !=: Eq 'a => ('a -> ('a -> bool)). Inequality comparison.

Field

Types supporting division in addition to ring operations.

Superclasses: Ring

Methods:

  • /: Field 'a => ('a -> ('a -> 'a)). Division.

Filterable

Functors supporting filtering and partial mapping.

Superclasses: Functor

Methods:

  • filter: Filterable 'f => (('a -> bool) -> (('f 'a) -> ('f 'a))). Keep elements that satisfy a predicate.
  • filter_map: Filterable 'f => (('a -> (Option 'b)) -> (('f 'a) -> ('f 'b))). Map and drop missing results in one pass.

Foldable

Containers that can be reduced with folds.

Superclasses: none

Methods:

  • foldl: Foldable 't => (('b -> ('a -> 'b)) -> ('b -> (('t 'a) -> 'b))). Strict left fold.
  • foldr: Foldable 't => (('a -> ('b -> 'b)) -> ('b -> (('t 'a) -> 'b))). Right fold.
  • fold: Foldable 't => (('b -> ('a -> 'b)) -> ('b -> (('t 'a) -> 'b))). Left-style fold over a container.

Functor

Type constructors that support structure-preserving mapping.

Superclasses: none

Methods:

  • map: Functor 'f => (('a -> 'b) -> (('f 'a) -> ('f 'b))). Apply a function to each value inside a functor.

Indexable

Containers that support indexed element access.

Superclasses: none

Methods:

  • get: Indexable ('t, 'a) => (i32 -> ('t -> 'a)). Get an element by index.

Integral

Integral numeric types supporting modulo.

Superclasses: none

Methods:

  • %: Integral 'a => ('a -> ('a -> 'a)). Remainder/modulo operation.

Monad

Applicatives supporting dependent sequencing (bind).

Superclasses: Applicative

Methods:

  • bind: Monad 'm => (('a -> ('m 'b)) -> (('m 'a) -> ('m 'b))). Monadic flat-map/sequencing operation.

MultiplicativeMonoid

Types with multiplicative identity and associative multiplication.

Superclasses: none

Methods:

  • one: MultiplicativeMonoid 'a => 'a. Multiplicative identity.
  • *: MultiplicativeMonoid 'a => ('a -> ('a -> 'a)). Multiplication.

Ord

Types with total ordering comparisons.

Superclasses: Eq

Methods:

  • cmp: Ord 'a => ('a -> ('a -> i32)). Three-way comparison returning negative/zero/positive i32.
  • <: Ord 'a => ('a -> ('a -> bool)). Less-than comparison.
  • <=: Ord 'a => ('a -> ('a -> bool)). Less-than-or-equal comparison.
  • >: Ord 'a => ('a -> ('a -> bool)). Greater-than comparison.
  • >=: Ord 'a => ('a -> ('a -> bool)). Greater-than-or-equal comparison.

Ring

Types supporting additive group plus multiplication.

Superclasses: AdditiveGroup, MultiplicativeMonoid

Methods:

Semiring

Types supporting additive and multiplicative monoid operations.

Superclasses: AdditiveMonoid, MultiplicativeMonoid

Methods:

Sequence

Ordered containers with slicing/zipping operations.

Superclasses: Functor, Foldable

Methods:

  • take: Sequence 'f => (i32 -> (('f 'a) -> ('f 'a))). Keep only the first n elements.
  • skip: Sequence 'f => (i32 -> (('f 'a) -> ('f 'a))). Drop the first n elements.
  • zip: Sequence 'f => (('f 'a) -> (('f 'b) -> ('f ('a, 'b)))). Pair elements from two containers by position.
  • unzip: Sequence 'f => (('f ('a, 'b)) -> (('f 'a), ('f 'b))). Split a container of pairs into a pair of containers.

Show

Types that can be converted to user-facing strings (Haskell-style naming).

Superclasses: none

Methods:

  • show: Show 'a => ('a -> string). Render a value as a human-readable string.

Built-in Functions

Overloaded (Type Class Methods)

FunctionSignatureImplemented OnDescription
negate('a -> 'a)i8
i16
i32
i64
f32
f64
Additive inverse.
-('a -> ('a -> 'a))i8
i16
i32
i64
f32
f64
Subtraction.
zero'astring
u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Additive identity.
+('a -> ('a -> 'a))string
u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Addition (or concatenation for strings).
or_else((('f 'a) -> ('f 'a)) -> (('f
'a) -> ('f 'a)))
List
Option
Array
(Result 'e)
Provide an alternative container value.
pure('a -> ('f 'a))List
Option
Array
(Result 'e)
Lift a plain value into an applicative context.
ap(('f ('a -> 'b)) -> (('f 'a)
-> ('f 'b)))
List
Option
Array
(Result 'e)
Apply wrapped functions to wrapped values.
default'abool
u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
(List 'a)
(Array 'a)
(Option 'a)
(Result 'a 'e)
Canonical default value for a type. For Result a e, this requires Default a.
==('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
bool
string
uuid
datetime
(List 'a)
(Option 'a)
(Array 'a)
(Result 'a 'e)
Equality comparison.
!=('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
bool
string
uuid
datetime
(List 'a)
(Option 'a)
(Array 'a)
(Result 'a 'e)
Inequality comparison.
/('a -> ('a -> 'a))f32
f64
Division.
filter(('a -> bool) -> (('f 'a) ->
('f 'a)))
List
Option
Array
Keep elements that satisfy a predicate.
filter_map(('a -> (Option 'b)) -> (('f
'a) -> ('f 'b)))
List
Option
Array
Map and drop missing results in one pass.
foldl(('b -> ('a -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Array
Strict left fold.
foldr(('a -> ('b -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Array
Right fold.
fold(('b -> ('a -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Array
Left-style fold over a container.
map(('a -> 'b) -> (('f 'a) -> ('f
'b)))
List
Option
Array
(Result 'e)
Apply a function to each value inside a functor.
get(i32 -> ('t -> 'a))((List 'a), 'a)
((Array 'a), 'a)
Get an element by index.
%('a -> ('a -> 'a))u8
u16
u32
u64
i8
i16
i32
i64
Remainder/modulo operation.
bind(('a -> ('m 'b)) -> (('m 'a)
-> ('m 'b)))
List
Option
Array
(Result 'e)
Monadic flat-map/sequencing operation.
one'au8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Multiplicative identity.
*('a -> ('a -> 'a))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Multiplication.
cmp('a -> ('a -> i32))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
Three-way comparison returning negative/zero/positive i32.
<('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
Less-than comparison.
<=('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
Less-than-or-equal comparison.
>('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
Greater-than comparison.
>=('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
Greater-than-or-equal comparison.
take(i32 -> (('f 'a) -> ('f 'a)))List
Array
Keep only the first n elements.
skip(i32 -> (('f 'a) -> ('f 'a)))List
Array
Drop the first n elements.
zip(('f 'a) -> (('f 'b) -> ('f
('a, 'b))))
List
Array
Pair elements from two containers by position.
unzip(('f ('a, 'b)) -> (('f 'a),
('f 'b)))
List
Array
Split a container of pairs into a pair of containers.
show('a -> string)bool
u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
uuid
datetime
(List 'a)
(Array 'a)
(Option 'a)
(Result 'a 'e)
Render a value as a human-readable string.

Other Built-ins

FunctionSignatureDescription
&&(bool -> (bool -> bool))Boolean conjunction.
Cons('a -> ((List 'a) -> (List
'a)))
Construct a non-empty list from head and tail.
Empty(List 'a)The empty list constructor.
Err('e -> (Result 't 'e))Construct a failed Result.
None(Option 't)The empty Option constructor.
Ok('t -> (Result 't 'e))Construct a successful Result.
Some('t -> (Option 't))Construct a present Option value.
countFoldable 'f => (('f 'a) ->
i32)
Count elements in a foldable container.
is_err((Result 't 'e) -> bool)Check whether a Result is Err.
is_none((Option 'a) -> bool)Check whether an Option is None.
is_ok((Result 't 'e) -> bool)Check whether a Result is Ok.
is_some((Option 'a) -> bool)Check whether an Option is Some.
maxFoldable 'f, Ord 'a => (('f
'a) -> 'a)
Maximum element by ordering.
meanFoldable 'f, Field 'a => (('f
'a) -> 'a)
Arithmetic mean over numeric foldables.
minFoldable 'f, Ord 'a => (('f
'a) -> 'a)
Minimum element by ordering.
sumFoldable 'f, AdditiveMonoid 'a
=> (('f 'a) -> 'a)
Sum all elements in a foldable container.
to_array((List 'a) -> (Array 'a))Convert a list to an array.
to_list((Array 'a) -> (List 'a))Convert an array to a list.
``