Expand description
Structure-preserving maps with composable proofs. Structure-preserving maps between types — morphisms in the categorical sense.
This module lifts what Backend already does (take an IacResource, produce
artifacts) into a composable, proof-bearing primitive. Every
synthesizer in the pipeline is a morphism from one typed domain to
another — IacType → RubyType, RubyType → String, IacResource → GeneratedArtifact — and when two morphisms compose, their proofs
compose with them.
§Why this exists
The platform’s 2,739-test proof engine attaches invariants to types
(IacType is injective to RubyType, render is deterministic, etc.).
But the glue between types — the actual transformation functions —
has been plain Rust fns. A plain fn carries no first-class proof;
proofs live in adjacent test files.
Morphism makes the transformation itself a value you can compose,
name, and attach invariants to. ProvenMorphism adds a
check_invariants hook: the morphism declares what must hold about
every (src, dst) pair it produces. Composition naturally inherits
both participants’ invariants.
§Minimal API
use iac_forge::morphism::{Morphism, Composed, ProvenMorphism};
struct Double;
impl Morphism<i64, i64> for Double {
fn name(&self) -> &'static str { "Double" }
fn apply(&self, x: &i64) -> i64 { x * 2 }
}
struct AddOne;
impl Morphism<i64, i64> for AddOne {
fn name(&self) -> &'static str { "AddOne" }
fn apply(&self, x: &i64) -> i64 { x + 1 }
}
let composed = Composed::new(Double, AddOne);
assert_eq!(composed.apply(&3), 7); // (3 * 2) + 1Structs§
- Composed
- Sequential composition:
A -> Bfollowed byB -> CgivesA -> C. - Identity
- Identity morphism — useful as a unit in composition chains and as the default transform in pipelines.
- Resource
Input - Wrapper identifying the (resource, provider) pair as a source value.
Traits§
- Morphism
- A structure-preserving map from
SrctoDst. - Proven
Morphism - A morphism that can verify its own invariants for a given (src, dst) pair.