build repr tree

This commit is contained in:
Michael Sippel 2024-09-01 23:56:37 +02:00
parent 0a6405b08e
commit 38c772389f
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -120,6 +120,32 @@ impl Context {
}
}
pub fn build_repr_tree(
&self,
rt: &Arc<RwLock<ReprTree>>,
root: TypeTerm,
leaves: Vec< TypeTerm >
) {
let mut st_problem = laddertypes::steiner_tree::PathApproxSteinerTreeSolver::new(
root,
leaves
);
if let Some( steiner_tree ) = st_problem.solve( &self.morphisms ) {
for morphism_type in steiner_tree.into_edges() {
eprintln!("--> apply morph to {}", self.type_term_to_str(&morphism_type.dst_type));
if let Some(( morphism, mut τ, σ )) =
self.morphisms.find_morphism_with_subtyping( &morphism_type )
{
let mut rt = rt.descend( τ ).expect("descend src repr");
(morphism.setup_projection)( &mut rt, &σ );
}
}
} else {
eprintln!("could not find steiner tree to build the requested repr tree");
}
}
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> Arc<RwLock<ReprTree>> {
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );