Skip to main content

Module map

Module map 

Source
Expand description

Inlean.Map: a hash map for Lean code, kept in a Rust HashMap.

In Lean the map is defined by a model: a list of entries in insertion order, searched with the key type’s ==. This module is the implementation the compiled code runs instead, and it must agree with the model on every operation. Two things make that possible. Entries are kept in insertion order, so listing the map has one defined result. And the index is keyed by Lean’s hash of a key and searched with Lean’s ==, both called through the instances the Lean code passes in, so “the same key” means here what it means in the model. A lawful hash (a == b → hash a = hash b, which the Lean side requires) guarantees that a key is always found in its own bucket.

Functions§

empty
The empty map.
entries⚠
The entries of a map, for a caller that owns nothing: each key and value is borrowed.
erase⚠
m without the entries whose key equals key. Consumes m; borrows the rest.
filter⚠
m with only the entries for which keep key value is true. Consumes m; borrows the function.
get_opt⚠
The value bound to a key equal to key, as an Option. Borrows everything.
insert⚠
m with key bound to value. An entry whose key equals key is replaced where it is, key included; otherwise the entry is added at the end. Consumes m, key and value; borrows the instances.
map_values⚠
A map with the keys of m, in the same order, each bound to f key value. Borrows both arguments.
size⚠
The number of entries, as a Nat.
to_list⚠
The entries in insertion order, as a List (κ × α). Borrows m.