diff options
Diffstat (limited to 'src/type/mod.rs')
-rw-r--r-- | src/type/mod.rs | 42 |
1 files changed, 31 insertions, 11 deletions
diff --git a/src/type/mod.rs b/src/type/mod.rs index 37081a1..aeeff93 100644 --- a/src/type/mod.rs +++ b/src/type/mod.rs @@ -48,6 +48,7 @@ pub enum TypeError { OtherError } +use Type::*; impl Type { /// Tests if the type has no variable types. @@ -56,21 +57,40 @@ impl Type { /// ```rust /// use melisp::r#type::{*, Type::*, TypeError::*, util::*}; /// - /// assert!(Integer.is_concrete()); - /// assert!(!VarType("a".to_string()).is_concrete()); + /// assert_eq!(Integer.is_concrete(), Ok(())); + /// assert_eq!( + /// VarType("a".to_string()).is_concrete(), + /// Err("a".to_string()) + /// ); /// - /// assert!(arr(Integer, Integer).is_concrete()); - /// assert!(!arr(VarType("b".to_string()), Integer).is_concrete()); + /// assert_eq!(arr(Integer, Integer).is_concrete(), Ok(())); + /// assert_eq!( + /// arr(VarType("b".to_string()), Integer).is_concrete(), + /// Err("b".to_string()) + /// ); /// - /// assert!( - /// List(vec![Integer, Integer, arr(Integer, Integer)]).is_concrete() + /// assert_eq!( + /// List(vec![Integer, Integer, arr(Integer, Integer)]).is_concrete(), + /// Ok(()) /// ); - /// assert!( - /// !List(vec![Integer, VarType("a".to_string()), Integer]) - /// .is_concrete() + /// assert_eq!( + /// List(vec![Integer, VarType("a".to_string()), Integer]) + /// .is_concrete(), + /// Err("a".to_string()) /// ); /// ``` - pub fn is_concrete(&self) -> bool { - todo!() + pub fn is_concrete(&self) -> Result<(), String> { + match self { + Integer => Ok(()), + Arrow(a, b) => b.is_concrete().and_then(|_ok| a.is_concrete()), + List(v) => { + let mut res = Ok(()); + for t in v { + res = res.and_then(|_ok| t.is_concrete()); + } + res + }, + VarType(s) => Err(s.clone()), + } } } |