check if term is empty

This commit is contained in:
Michael Sippel 2024-10-06 14:39:05 +02:00
parent 96c523ada1
commit 619c2dc3e4
Signed by: senvas
GPG key ID: F96CF119C34B64A6

View file

@ -2,7 +2,7 @@ use {
crate::{TypeTerm, TypeID, parser::ParseLadderType}
};
#[derive(Clone)]
#[derive(Clone, PartialEq)]
pub enum SugaredTypeTerm {
TypeID(TypeID),
Num(i64),
@ -92,5 +92,23 @@ impl SugaredTypeTerm {
).collect()),
}
}
pub fn is_empty(&self) -> bool {
match self {
SugaredTypeTerm::TypeID(_) => false,
SugaredTypeTerm::Num(_) => false,
SugaredTypeTerm::Char(_) => false,
SugaredTypeTerm::Univ(t) => t.is_empty(),
SugaredTypeTerm::Spec(ts) |
SugaredTypeTerm::Ladder(ts) |
SugaredTypeTerm::Func(ts) |
SugaredTypeTerm::Morph(ts) |
SugaredTypeTerm::Struct(ts) |
SugaredTypeTerm::Enum(ts) |
SugaredTypeTerm::Seq(ts) => {
ts.iter().fold(true, |s,t|s&&t.is_empty())
}
}
}
}