Skip to content

aivi.prelude

The aivi.prelude module is AIVI's convenience layer — it re-exports the most commonly used functions from across the standard library.

Because aivi.prelude declares hoist, all of its exports are automatically available in every AIVI file. You do not need a use aivi.prelude (...) declaration. Types like Int, Bool, Text, List, Option, Result, and type class constraints like Eq, Ord, Functor, and more are simply in scope everywhere.

At a glance

aivi.prelude is already a scan-first module page: the tables below list the types, classes, and representative helper batteries that are available everywhere by default. Use this page as the overview map; use the module pages like aivi.option, aivi.result, and aivi.list when you need the full per-module battery tables.

Built-in Types

These types are always available and can be imported from aivi.prelude:

TypeDescription
Int64-bit signed integer
Float64-bit floating point
DecimalArbitrary-precision decimal
BigIntArbitrary-precision integer
BoolBoolean: True or False
TextUnicode text string
UnitThe unit type (no value)
OrderingResult of comparison: Less, Equal, or Greater
List AOrdered collection
Option AOptional value: Some value or None
Result E ASuccess or failure: Ok value or Err error
Validation E AAccumulating validation: Valid value or Invalid errors
Signal AA reactive value that changes over time
Task E AA one-shot async computation description

Type Classes

ClassDescription
Eq AEquality comparison
Ord AOrdering and comparison via compare : A -> A -> Ordering; ordinary <, >, <=, and >= derive from this member
Default AA default value
Functor FMappable container
Apply FEffectful function application
Applicative FApplicative functor
Chain MDependent sequencing without changing the carrier family
Monad FMonadic sequencing (List, Option, Result, and Task are the builtin executable carriers today)
Foldable FFoldable container
Traversable FTraversable container
Filterable FFilterable container
Semigroup AAssociative combination
Monoid ASemigroup with identity
Bifunctor FMappable over both type parameters

For the current higher-kinded hierarchy, the canonical executable support reference, and the current unary imported-instance slice for user-authored higher-kinded classes and instances, see Typeclasses & Higher-Kinded Support. For the law contract behind those classes, see Class Laws & Design Boundaries. Parser or checker acceptance alone does not imply executable runtime support.

Option Functions

aivi
use aivi.prelude (
    Option
    Text
    Bool
    getOrElse
    isSome
    isSomeAnd
    mapOr
    textNonEmpty
)

value name : Option Text = Some "Ada"
value displayName : Text = getOrElse "guest" name
value hasName : Bool = isSome name

type Text -> Text
func punctuate = name =>
    append name "!"

value foldedName : Text = mapOr "guest" punctuate name
value checkedName : Bool = isSomeAnd textNonEmpty name

Result Functions

aivi
value age : Result Text Int = Ok 30
value ageValue : Int = withDefault 0 age
value succeeded : Bool = isOk age

Validation Functions

aivi
use aivi.prelude (
    Text
    Validation
    isValid
    validationToResult
    validationGetOrElse
)

value checked : Validation Text Text = Valid "Ada"
value passed : Bool = isValid checked
value checkedText : Text = validationGetOrElse "guest" checked
value checkedResult : Result Text Text = validationToResult checked

List Functions

aivi
use aivi.prelude (
    Int
    Text
    Bool
    List
    length
    head
    isEmpty
    indexed
)

value items : List Text = [
    "Ada",
    "Grace",
    "Hedy"
]

value count : Int = length items
value first : Option Text = head items
value empty : Bool = isEmpty []
value indexedItems : List (Int, Text) = indexed items
aivi
use aivi.prelude (
    Int
    mapWithIndex
    reduceWithIndex
)

type Int -> Int -> Int
func addIndex = index item =>
    index + item

type Int -> Int -> Int -> Int
func addIndexed = total index item =>
    total + index + item

value adjusted : List Int =
    mapWithIndex addIndex [
        10,
        20,
        30
    ]

value indexedTotal : Int =
    reduceWithIndex addIndexed 0 [
        10,
        20,
        30
    ]

Order Functions

Ord.compare is the primitive ordering member in the prelude. Any type with an Ord instance can use min, max, minOf, and the ordinary ordering operators directly.

aivi
value smallest : Int = min 5 3
value greatest : Int = max 5 3

value leastOf : Int =
    minOf 10 [
        7,
        4,
        9
    ]

Text Functions

Prelude keeps bare join for the generic Monad.join member. Text joining stays on aivi.text.join, which you can import locally when needed.

aivi
use aivi.text (join as textJoin)

value csv : Text =
    textJoin ", " [
        "Ada",
        "Grace",
        "Hedy"
    ]

value combined : Text =
    textJoin "" [
        "Hello",
        " ",
        "World"
    ]

value wrapped : Text = surround "(" ")" "AIVI"

Math Functions

aivi
value absolute : Int = abs (-5)
value flipped : Int = negate 7
value even : Bool = isEven 4
value clamped : Int = clamp 0 100 150
value inRange : Bool = between 1 10 5

Bool Functions

aivi
value inverted : Bool = not True
value exclusive : Bool = xor True False

Pair Functions

aivi
value pair : (Int, Text) = (
    42,
    "hello"
)

value firstValue : Int = first pair
value secondValue : Text = second pair
value swapped : (Text, Int) = swap pair

(c) 2026 by Andreas Herd