reactivate find_morphism()

This commit is contained in:
Michael Sippel 2025-02-25 22:54:18 +01:00
parent 19e29759d2
commit 4e89eeda91
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -1,8 +1,6 @@
use {
crate::{
unification::UnificationProblem, TypeDict, TypeID, TypeTerm,
pretty::*,
sugar::SugaredTypeTerm,
subtype_unify, sugar::SugaredTypeTerm, unification::UnificationProblem, unparser::*, TypeDict, TypeID, TypeTerm
},
std::{collections::HashMap, u64}
};
@ -135,13 +133,17 @@ impl<M: Morphism + Clone> MorphismBase<M> {
]));
}
dst_types.push(
MorphismInstance {
halo: TypeTerm::Ladder(dst_halo_ladder).normalize(),
m: item_morph_inst.m.map_morphism(seq_type.clone()).expect("couldnt get map morphism"),
σ: item_morph_inst.σ
}
);
if let Some( map_morph ) = item_morph_inst.m.map_morphism( seq_type.clone() ) {
dst_types.push(
MorphismInstance {
halo: TypeTerm::Ladder(dst_halo_ladder).normalize(),
m: map_morph,
σ: item_morph_inst.σ
}
);
} else {
eprintln!("could not get map morphism");
}
}
}
}
@ -245,28 +247,54 @@ impl<M: Morphism + Clone> MorphismBase<M> {
None
}
/*
pub fn find_direct_morphism(&self, ty: &MorphismType) -> Option< (M, HashMap<TypeID, TypeTerm>) > {
for m in self.morphisms.iter() {
let unification_problem = UnificationProblem::new(
vec![
( ty.src_type.clone(), m.get_type().src_type.clone() ),
( m.get_type().dst_type.clone(), ty.dst_type.clone() )
]
);
let unification_result = unification_problem.solve_subtype();
if let Ok((halo, σ)) = unification_result {
return Some((m.clone(), σ));
pub fn find_direct_morphism(&self,
ty: &MorphismType,
dict: &mut impl TypeDict
) -> Option< MorphismInstance<M> > {
eprintln!("find direct morph");
for m in self.morphisms.iter() {
let ty = ty.clone().normalize();
let morph_type = m.get_type().normalize();
eprintln!("find direct morph:\n {} <= {}",
dict.unparse(&ty.src_type), dict.unparse(&morph_type.src_type),
);
if let Ok((halo, σ)) = subtype_unify(&ty.src_type, &morph_type.src_type) {
eprintln!("halo: {}", dict.unparse(&halo));
let dst_type = TypeTerm::Ladder(vec![
halo.clone(),
morph_type.dst_type.clone()
]);
eprintln!("-----------> {} <= {}",
dict.unparse(&dst_type), dict.unparse(&ty.dst_type)
);
/*
let unification_problem = UnificationProblem::new(
vec![
( ty.src_type, morph_type.src_type ),
( morph_type.dst_type, ty.dst_type )
]
);*/
if let Ok((halo2, σ2)) = subtype_unify(&dst_type, &ty.dst_type) {
eprintln!("match. halo2 = {}", dict.unparse(&halo2));
return Some(MorphismInstance {
m: m.clone(),
halo: halo2,
σ,
});
}
}
}
None
}
pub fn find_map_morphism(&self, ty: &MorphismType) -> Option< (M, HashMap<TypeID, TypeTerm>) > {
pub fn find_map_morphism(&self, ty: &MorphismType, dict: &mut impl TypeDict) -> Option< MorphismInstance<M> > {
for seq_type in self.seq_types.iter() {
eprintln!("try seq type {:?}", seq_type);
if let Ok((halo, σ)) = UnificationProblem::new(vec![
(ty.src_type.clone().param_normalize(),
TypeTerm::App(vec![ seq_type.clone(), TypeTerm::TypeID(TypeID::Var(100)) ])),
@ -281,9 +309,13 @@ impl<M: Morphism + Clone> MorphismBase<M> {
}.normalize();
//eprintln!("Map Morph: try to find item-morph with type {:?}", item_morph_type);
if let Some((m, σ)) = self.find_morphism( &item_morph_type ) {
if let Some(list_morph) = m.map_morphism( seq_type.clone() ) {
return Some( (list_morph, σ) );
if let Some(item_morph_inst) = self.find_morphism( &item_morph_type, dict ) {
if let Some( list_morph ) = item_morph_inst.m.map_morphism( seq_type.clone() ) {
return Some( MorphismInstance {
m: list_morph,
σ,
halo
} );
}
}
}
@ -292,17 +324,18 @@ impl<M: Morphism + Clone> MorphismBase<M> {
None
}
pub fn find_morphism(&self, ty: &MorphismType)
-> Option< ( M, HashMap<TypeID, TypeTerm> ) > {
if let Some((m,σ)) = self.find_direct_morphism(ty) {
return Some((m,σ));
pub fn find_morphism(&self, ty: &MorphismType,
dict: &mut impl TypeDict
)
-> Option< MorphismInstance<M> > {
if let Some(m) = self.find_direct_morphism(ty, dict) {
return Some(m);
}
if let Some((m,σ)) = self.find_map_morphism(ty) {
return Some((m, σ));
if let Some(m) = self.find_map_morphism(ty, dict) {
return Some(m);
}
None
}
*/
}
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>\\