From 2c2268c918c7895b66f5fcb3827277a8a8e90bc5 Mon Sep 17 00:00:00 2001 From: Michael Sippel Date: Sun, 3 Nov 2024 01:39:57 +0100 Subject: [PATCH] repr tree: create reprtree with a single path from type ladder --- lib-nested-core/src/repr_tree/node.rs | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/lib-nested-core/src/repr_tree/node.rs b/lib-nested-core/src/repr_tree/node.rs index bc51906..837092e 100644 --- a/lib-nested-core/src/repr_tree/node.rs +++ b/lib-nested-core/src/repr_tree/node.rs @@ -50,15 +50,19 @@ impl std::fmt::Debug for ReprTree { //<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>> impl ReprTree { - pub fn new(type_tag: impl Into) -> Self { - let type_tag = type_tag.into(); + pub fn new(typ: impl Into) -> Self { + let mut lnf = typ.into().get_lnf_vec(); + let head_type = lnf.remove(0); + + let mut branches = HashMap::new(); + if lnf.len() > 0 { + branches.insert( lnf[0].clone(), ReprTree::new_arc(TypeTerm::Ladder(lnf)) ); + } - assert!(type_tag.is_flat()); - ReprTree { halo: TypeTerm::unit(), - type_tag: type_tag.clone(), - branches: HashMap::new(), + type_tag: head_type, + branches, leaf: None } }