about summary refs log tree commit diff
path: root/src/interpreter/value.rs
diff options
context:
space:
mode:
authorGriffin Smith <root@gws.fyi>2021-03-14T20·43-0400
committerGriffin Smith <root@gws.fyi>2021-03-14T20·43-0400
commitecb4c0f803e9b408e4fd21c475769eb4dc649d14 (patch)
tree80390b00a6009cea21fbb68cbf56e6a193b478a2 /src/interpreter/value.rs
parent7960c3270e1a338f4da40d044a6896df96d82c79 (diff)
Universally quantified type variables
Implement universally quantified type variables, both explicitly given
by the user and inferred by the type inference algorithm.
Diffstat (limited to 'src/interpreter/value.rs')
-rw-r--r--src/interpreter/value.rs20
1 files changed, 10 insertions, 10 deletions
diff --git a/src/interpreter/value.rs b/src/interpreter/value.rs
index a1a579aec8db..55ba42f9de58 100644
--- a/src/interpreter/value.rs
+++ b/src/interpreter/value.rs
@@ -13,9 +13,9 @@ use crate::ast::{FunctionType, Ident, Type};
 
 #[derive(Debug, Clone)]
 pub struct Function<'a> {
-    pub type_: FunctionType,
+    pub type_: FunctionType<'a>,
     pub args: Vec<Ident<'a>>,
-    pub body: Expr<'a, Type>,
+    pub body: Expr<'a, Type<'a>>,
 }
 
 #[derive(From, TryInto)]
@@ -100,7 +100,7 @@ impl<'a> Val<'a> {
         &'b T: TryFrom<&'b Self>,
     {
         <&T>::try_from(self).map_err(|_| Error::InvalidType {
-            actual: self.type_(),
+            actual: self.type_().to_owned(),
             expected: <T as TypeOf>::type_of(),
         })
     }
@@ -109,8 +109,8 @@ impl<'a> Val<'a> {
         match self {
             Val::Function(f) if f.type_ == function_type => Ok(&f),
             _ => Err(Error::InvalidType {
-                actual: self.type_(),
-                expected: Type::Function(function_type),
+                actual: self.type_().to_owned(),
+                expected: Type::Function(function_type.to_owned()),
             }),
         }
     }
@@ -175,29 +175,29 @@ impl<'a> Div for Value<'a> {
 }
 
 pub trait TypeOf {
-    fn type_of() -> Type;
+    fn type_of() -> Type<'static>;
 }
 
 impl TypeOf for i64 {
-    fn type_of() -> Type {
+    fn type_of() -> Type<'static> {
         Type::Int
     }
 }
 
 impl TypeOf for bool {
-    fn type_of() -> Type {
+    fn type_of() -> Type<'static> {
         Type::Bool
     }
 }
 
 impl TypeOf for f64 {
-    fn type_of() -> Type {
+    fn type_of() -> Type<'static> {
         Type::Float
     }
 }
 
 impl TypeOf for String {
-    fn type_of() -> Type {
+    fn type_of() -> Type<'static> {
         Type::CString
     }
 }