Baskerville.Kernel
- Package
- purescript-baskerville-core
- Repository
- afcondon/purescript-baskerville
The proof-term kernel: facts with justifications, hash-consed into a derivation DAG.
A Fact is a proof term — a node of the free algebra generated by the
client's rules-as-constructors over its observation axioms. Recording a
claim already known keeps the first justification (hash-consing), which
is what makes the free tree a shared DAG. Premises always point at
strictly smaller FactIds (they cite facts that already existed), so
the DAG is acyclic by construction.
Type parameters, everywhere in this library:
claim— the client's atomic statements (finite,Ord).rule— the client's rule names, an ADT so the UI can say them.axiom— anchors: the non-fact provenance a client threads through (event ids, timestamps, "given"), on axioms and derivations alike.residue— the client's residue: lattice state that refines between facts (candidate sets shrinking) without itself earningFactIds. Clients on the plain powerset instance useUnit.
#Fact Source
type Fact claim rule axiom = { alsoWhy :: Array (Why rule axiom), claim :: claim, id :: FactId, why :: Why rule axiom }why is the primary justification — first derivation wins — and the
only one the acyclicity guarantee covers: its premises point at
strictly smaller ids. alsoWhy records every other way the claim
was later rederived. Those may cite facts born after this one, so
they are evidence of rederivability, not independently well-founded
proofs — checking an alternative for well-founded support is ATMS
work (extensions catalogue #7). Recording them now is what keeps
that door open, and it is what lets a UI say "X-wing sees it too".
#addFact Source
addFact :: forall residue claim rule axiom. Ord claim => Eq rule => Eq axiom => { claim :: claim, why :: Why rule axiom } -> KB residue claim rule axiom -> KB residue claim rule axiomRecord a claim. News gets a fresh fact; a claim already on the feed
keeps its place and its primary justification, and the new derivation
is appended to alsoWhy if it is genuinely different — so a claim
rederivable six ways appears once, remembering all six.
#justificationsFor Source
justificationsFor :: forall residue claim rule axiom. Ord claim => claim -> KB residue claim rule axiom -> Array (Why rule axiom)Every recorded justification for a claim, primary first.
#sameDerivation Source
sameDerivation :: forall rule axiom. Eq rule => Eq axiom => Why rule axiom -> Why rule axiom -> BooleanDerivation identity: what individuates a justification is its content
— the rule and what it consumed — not source, which only records
when the inference was first noticed. Rederiving the same conclusion
from the same premises while processing a later event is the same
derivation, and addFact must not collect it twice.
#subsumes Source
subsumes :: forall residue claim rule axiom. Ord claim => KB residue claim rule axiom -> KB residue claim rule axiom -> BooleanDoes the first mind know everything the second does? This is the law perspectives obey in a monotone system: a mind that witnessed a superset of the observations derives a superset of the claims. Perspectives themselves are client code (observation projection is domain vocabulary — see kibitzer's Observe); the library owns the property they must satisfy, and clients pin it over random streams.
#knownClaims Source
knownClaims :: forall residue claim rule axiom. KB residue claim rule axiom -> Set claim#withResidue Source
withResidue :: forall residue claim rule axiom. (residue -> residue) -> KB residue claim rule axiom -> KB residue claim rule axiom