Lattice Algebra in KindScript
This post demonstrates the new interactive learning features on this site. Below are embedded flashcards, interactive diagrams, and a downloadable Anki deck.
The Containment Lattice
KindScript's CodeLoc type forms a three-level containment hierarchy. This visualization shows how directories contain files, which contain declarations.
Every line in the diagram represents the subsumes relation — the upper element contains the lower element.
The Powerset Lattice
Oxide (the Rust formalization) uses a classic powerset lattice structure. Regions are elements of P(Loans), ordered by subset inclusion.
Oxide's region algebra is this structure: P(Loans) ordered by ⊆. Meet = ∩, Join = ∪. A complete Boolean algebra.
This is a complete Boolean algebra — the strongest kind of lattice. It has complements, distributes over arbitrary unions and meets, and every subset has a join and meet.
Set Operations
The carrier algebra resolves to sets of code locations. Three core operations compose these sets:
Union
unionLocs
The directory subsumes both files after merge, so canonicalization removes them.
Union merges two sets and canonicalizes the result — removing locations that are subsumed by coarser locations already in the set.
Intersection
intersectLocs
meet(dir, decl) = decl (dir contains it) — meet(dir, infra/db.ts) = null (different tree)
Intersection computes the pairwise lattice meet of elements from both sets, keeping only non-null results.
Exclusion
excludeLocs
Each base location is checked: is it subsumed by any excluded location? If yes, it's dropped.
Exclusion removes elements from the base set that are subsumed by any element in the excluded set.
Key Insight: Form Independence
The checker operates on these resolved location sets uniformly — it never inspects the CarrierExpr that produced them. This is form independence: architectural properties don't depend on whether code is organized by folders, annotations, globs, or packages.
In Oxide (Rust's formalization), the same principle holds: the borrow checker validates ownership invariants against concrete loan sets, not against how those regions were inferred. Safety is a property of the resolved set, not of the expression that computed it.
Want to Review These Later?
You can download all the flashcards from this post as an Anki deck, or use the built-in spaced repetition system at /learn.
Flashcards Available
This post includes 5 flashcards for spaced repetition. Download the deck to import into Anki.
How to import into Anki
- Download the .txt file above
- Open Anki and click Import
- Select the downloaded file
- Choose Basic card type
- Ensure fields map to Front and Back
- Click Import