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
Dict aDictionary/record-like mapping from field labels to values.
List aImmutable ordered sequence. 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.

Superclasses: Subtractive

Methods:

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

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.

Divisive

Types supporting division.

Superclasses: MultiplicativeMonoid

Methods:

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

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, Divisive

Methods:

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.

Subtractive

Types supporting binary subtraction.

Superclasses: Semiring

Methods:

  • -: Subtractive 'a => ('a -> ('a -> 'a)). Subtraction.

Built-in Functions

Overloaded (Type Class Methods)

FunctionSignatureImplemented OnDescription
negate('a -> 'a)i8
i16
i32
i64
f32
f64
Additive inverse.
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
(Result 'e)
Provide an alternative container value.
pure('a -> ('f 'a))List
Option
(Result 'e)
Lift a plain value into an applicative context.
ap(('f ('a -> 'b)) -> (('f 'a)
-> ('f 'b)))
List
Option
(Result 'e)
Apply wrapped functions to wrapped values.
default'abool
u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
string
(List 'a)
(Option 'a)
(Result 'a 'e)
Canonical default value for a type. For Result a e, this requires Default a.
/('a -> ('a -> 'a))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Division.
==('a -> ('a -> bool))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
bool
string
uuid
datetime
(List 'a)
(Option '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)
(Result 'a 'e)
Inequality comparison.
filter(('a -> bool) -> (('f 'a) ->
('f 'a)))
List
Option
Keep elements that satisfy a predicate.
filter_map(('a -> (Option 'b)) -> (('f
'a) -> ('f 'b)))
List
Option
Map and drop missing results in one pass.
foldl(('b -> ('a -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Strict left fold.
foldr(('a -> ('b -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Right fold.
fold(('b -> ('a -> 'b)) -> ('b ->
(('t 'a) -> 'b)))
List
Option
Left-style fold over a container.
map(('a -> 'b) -> (('f 'a) -> ('f
'b)))
List
Option
(Result 'e)
Apply a function to each value inside a functor.
get(i32 -> ('t -> 'a))((List '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
(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)))ListKeep only the first n elements.
skip(i32 -> (('f 'a) -> ('f 'a)))ListDrop the first n elements.
zip(('f 'a) -> (('f 'b) -> ('f
('a, 'b))))
ListPair elements from two containers by position.
unzip(('f ('a, 'b)) -> (('f 'a),
('f 'b)))
ListSplit 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)
(Option 'a)
(Result 'a 'e)
Render a value as a human-readable string.
-('a -> ('a -> 'a))u8
u16
u32
u64
i8
i16
i32
i64
f32
f64
Subtraction.

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.
first(i32 -> ((List 'a) -> (List
'a)))
Return the first n list elements; errors if n is out of range.
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.
last(i32 -> ((List 'a) -> (List
'a)))
Return the last n list elements; errors if n is out of range.
lengthFoldable 'f => (('f 'a) ->
i32)
Return the number of elements in a foldable container.
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.
slice(i32 -> (i32 -> ((List 'a) ->
(List 'a))))
Return elements in the half-open range n..m; errors if either bound is out of range or m < n.
sumFoldable 'f, AdditiveMonoid 'a
=> (('f 'a) -> 'a)
Sum all elements in a foldable container.
unwrap((Option 'a) -> 'a)

((Result 't 'e) -> 't)
Extract the inner value from Some/Ok, or raise an error for None/Err.
``