Expand description
The Rust functions behind the collections of inlean’s Lean library: the standard
library’s Vec, VecDeque, HashMap and HashSet.
In a block such a collection is the Rust collection itself, held in a Lean object, and
each of its operations is a declaration that one of these functions runs for. The function
is trusted to compute what the operation’s model in Inlean.lean says; the two are tested
against each other and against Lean’s own collections.
The functions are generic and name no element type. Generated code calls each with the
Rust values of the arguments, and rustc finds the types from the collection. A collection
or an index that Lean lends arrives as a reference. An element that Lean lends arrives as
impl Borrow<T>: a reference where the element is an object, and the value itself where
it is a number, which Lean never lends.
What a Lean object holds for a collection is the collection, or an Arc of it where the
block says instantiate ... as Arc. Each function takes either, as a Slot.
A function that Lean passes arrives as a closure, which takes the elements by reference: each call makes Lean values of them. A fold is generic in what it accumulates, as its Lean declaration is, and only passes it between the calls.
Modules§
- hash_
map HashMap<K, V>, whose model is what it holds and the shape its order depends on.- hash_
set HashSet<K>, whose model is what it holds and the shape its order depends on. Whathash_mapsays of maps holds here.- vec
Vec<T>, whose model is the array of its elements.- vec_
deque VecDeque<T>, whose model is the array of its elements from front to back.
Traits§
- Slot
- What holds a collection of type
Tin a Lean object: the collection itself, or anArcof it. AnArcis shared by a pointer, so that a collection kept in two places, or read out of another collection, is not copied; one of two holders that changes it gets a copy of its own first, which is what Lean does with a value it holds twice.