diff options
Diffstat (limited to 'src/type/mod.rs')
-rw-r--r-- | src/type/mod.rs | 34 |
1 files changed, 33 insertions, 1 deletions
diff --git a/src/type/mod.rs b/src/type/mod.rs index 5e7076a..6c4be97 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -17,7 +17,10 @@ pub enum Type { List(Vec<Type>), - UndefinedType, // only for errors + /// Type for generics + /// and also error messages + /// with unknown types + VarType(String), } @@ -27,6 +30,8 @@ pub enum TypeError { UndefinedVariable(String), + UnboundGeneric(String), + InvalidOperator { operator: SExp, expected: Type, @@ -41,3 +46,30 @@ pub enum TypeError { OtherError } + + +impl Type { + /// Tests if the type has no variable types. + /// + /// **Examples** + /// ```rust + /// use melisp::r#type::{*, Type::*, TypeError::*, util::*}; + /// + /// assert!(Integer.is_concrete()); + /// assert!(!VarType("a".to_string()).is_concrete()); + /// + /// assert!(arr(Integer, Integer).is_concrete()); + /// assert!(!arr(VarType("b".to_string()), Integer).is_concrete()); + /// + /// assert!( + /// List(vec![Integer, Integer, arr(Integer, Integer)]).is_concrete() + /// ); + /// assert!( + /// !List(vec![Integer, VarType("a".to_string()), Integer]) + /// .is_concrete() + /// ); + /// ``` + pub fn is_concrete(&self) -> bool { + todo!() + } +} |