Skip to content

aivi.core.dict ​

aivi.core.dict provides an immutable association map for keys with an Eq instance. A Dict K V stores entries in a list, so lookup, insertion, and removal take linear time. Building a dictionary with repeated insertion can take quadratic time. Use it for small maps in the MVP.

The empty dictionary is { entries: [] }. insert places a new or replaced key first. fromList processes pairs from left to right, so the final occurrence of a duplicate key wins and appears first.

Type class operations ​

Dict K implements Functor, Foldable, Traversable, and Filterable. Ambient map transforms values, reduce folds them in entry order, and filterMap removes entries whose transformed value is None. Keys and the relative order of retained entries are preserved. Default (Dict K V) creates an empty dictionary. These operations do not require Eq K because they never compare or insert keys.

traverse transform dictionary sequences values through any Applicative G, producing G (Dict K B). Every resulting dictionary keeps the original keys and entry order. An empty dictionary is lifted with pure. Task effects run in entry order when the plan is executed.

mapValues remains the explicitly named equivalent of map. There is no implicit class-level merge policy for dictionaries.

API ​

ExportTypeBehavior
DictDict K VAssociation-map record type
singletonK -> V -> Dict K VCreate one entry
insertEq K => K -> V -> Dict K V -> Dict K VInsert or replace a value
insertWithEq K => (V -> V -> V) -> K -> V -> Dict K V -> Dict K VCombine an existing value with a new value
getEq K => K -> Dict K V -> Option VLook up a key
getWithDefaultEq K => V -> K -> Dict K V -> VLook up a key with a fallback
memberEq K => K -> Dict K V -> BoolTest whether a key exists
removeEq K => K -> Dict K V -> Dict K VRemove a key
sizeDict K V -> IntCount entries
keysDict K V -> List KReturn keys in entry order
valuesDict K V -> List VReturn values in entry order
toListDict K V -> List (K, V)Return key/value pairs in entry order
fromListEq K => List (K, V) -> Dict K VBuild a dictionary from pairs
mapValues(V1 -> V2) -> Dict K V1 -> Dict K V2Transform every value
filterValues(V -> Bool) -> Dict K V -> Dict K VKeep entries whose values pass a predicate
aivi
use aivi.core.dict (
    Dict
    get
    insert
)

value scores : Dict Text Int =
    insert "Ada" 10 {
        entries: []
    }

value adaScore : Option Int = get "Ada" scores

(c) 2026 by Andreas Herd