build repr tree
This commit is contained in:
parent
0a6405b08e
commit
38c772389f
1 changed files with 26 additions and 0 deletions
|
@ -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>> {
|
pub fn make_repr(ctx: &Arc<RwLock<Self>>, t: &TypeTerm) -> Arc<RwLock<ReprTree>> {
|
||||||
let rt = Arc::new(RwLock::new(ReprTree::new( TypeTerm::unit() )));
|
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() } );
|
ctx.read().unwrap().apply_morphism( &rt, &MorphismType{ src_type: TypeTerm::unit(), dst_type: t.clone() } );
|
||||||
|
|
Loading…
Reference in a new issue