add term, dict & bimap
This commit is contained in:
parent
e12cbef99f
commit
2f26dcc936
4 changed files with 159 additions and 5 deletions
src
68
src/term.rs
Normal file
68
src/term.rs
Normal file
|
@ -0,0 +1,68 @@
|
|||
use {
|
||||
crate::TypeID,
|
||||
std::collections::HashMap
|
||||
};
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
#[derive(Clone, PartialEq, Eq, Hash, Debug)]
|
||||
pub enum TypeTerm {
|
||||
|
||||
/* Atomic Terms */
|
||||
|
||||
// Base types from dictionary
|
||||
TypeID(TypeID),
|
||||
|
||||
// Literals
|
||||
Num(i64),
|
||||
Char(char),
|
||||
|
||||
|
||||
|
||||
/* Complex Terms */
|
||||
|
||||
// Type Parameters
|
||||
// avoid currying to save space & indirection
|
||||
App(Vec< TypeTerm >),
|
||||
|
||||
// Type Ladders
|
||||
Ladder(Vec< TypeTerm >),
|
||||
}
|
||||
|
||||
//<<<<>>>><<>><><<>><<<*>>><<>><><<>><<<<>>>>
|
||||
|
||||
impl TypeTerm {
|
||||
pub fn unit() -> Self {
|
||||
TypeTerm::Ladder(vec![])
|
||||
}
|
||||
|
||||
pub fn new(id: TypeID) -> Self {
|
||||
TypeTerm::TypeID(id)
|
||||
}
|
||||
|
||||
pub fn arg(&mut self, t: impl Into<TypeTerm>) -> &mut Self {
|
||||
match self {
|
||||
TypeTerm::App(args) => {
|
||||
args.push(t.into());
|
||||
}
|
||||
|
||||
_ => {
|
||||
*self = TypeTerm::App(vec![
|
||||
self.clone(),
|
||||
t.into()
|
||||
])
|
||||
}
|
||||
}
|
||||
|
||||
self
|
||||
}
|
||||
|
||||
pub fn num_arg(&mut self, v: i64) -> &mut Self {
|
||||
self.arg(TypeTerm::Num(v))
|
||||
}
|
||||
|
||||
pub fn char_arg(&mut self, c: char) -> &mut Self {
|
||||
self.arg(TypeTerm::Char(c))
|
||||
}
|
||||
}
|
||||
|
Loading…
Add table
Add a link
Reference in a new issue