Skip to content

aivi.core.set ​

aivi.core.set provides immutable sets for values with an Eq instance. A Set A is list-backed, so membership and updates take linear time and fromList can take quadratic time. Use it for small membership collections in the MVP.

The public representation is { items: List A }, but direct record construction can contain duplicates. singleton, insert, and fromList preserve uniqueness and insertion order.

Type class operations ​

This module's Set implements Foldable: ambient reduce visits each member once in insertion order. Default (Set A) creates an empty set. These operations need no equality comparisons.

An unrestricted Functor Set would need equality evidence for the mapped element type and could merge distinct members. Use operations that make that change of membership explicit.

API ​

ExportTypeBehavior
SetSet AList-backed set record type
isEmptySet A -> BoolTest whether the set has no items
singletonA -> Set ACreate a one-item set
memberEq A => A -> Set A -> BoolTest membership
insertEq A => A -> Set A -> Set AAdd an item if absent
removeEq A => A -> Set A -> Set ARemove an item if present
sizeSet A -> IntCount items
toListSet A -> List AReturn items in insertion order
fromListEq A => List A -> Set ABuild a set and discard duplicates
aivi
use aivi.core.set (
    Set
    fromList
    member
)

value tags : Set Text =
    fromList [
        "work",
        "urgent",
        "work"
    ]

value isUrgent : Bool = member "urgent" tags

(c) 2026 by Andreas Herd