From be175a2b7551f0248f3401aa44f7a13ad3f6cfad Mon Sep 17 00:00:00 2001 From: greg Date: Sat, 23 Feb 2019 00:59:58 -0800 Subject: [PATCH] Add more infrastructure for unify --- schala-lang/language/src/typechecking.rs | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/schala-lang/language/src/typechecking.rs b/schala-lang/language/src/typechecking.rs index d3edbb0..14c70a9 100644 --- a/schala-lang/language/src/typechecking.rs +++ b/schala-lang/language/src/typechecking.rs @@ -4,7 +4,7 @@ use std::rc::Rc; // -nope, ghc deliberately does typechecking before desugaring to core // cf. a history of haskell, peyton-jones -use ena::unify::{UnifyKey, InPlaceUnificationTable, UnificationTable}; +use ena::unify::{UnifyKey, InPlaceUnificationTable, UnificationTable, EqUnifyValue}; use crate::ast::*; use crate::util::ScopeStack; @@ -60,13 +60,13 @@ pub enum Type { pub struct TypeVar(usize); impl UnifyKey for TypeVar { - type Value = (); + type Value = Option; fn index(&self) -> u32 { self.0 as u32 } fn from_index(u: u32) -> TypeVar { TypeVar(u as usize) } fn tag() -> &'static str { "TypeVar" } } -#[derive(Debug, Clone, PartialEq)] +#[derive(Debug, Clone, PartialEq, Eq)] pub enum TypeConst { Unit, Nat, @@ -78,6 +78,8 @@ pub enum TypeConst { UserDefined } +impl EqUnifyValue for TypeConst { } + macro_rules! ty { ($type_name:ident) => { Type::Const(TypeConst::$type_name) }; ($t1:ident -> $t2:ident) => { Type::Arrow(Box::new(ty!($t1)), Box::new(ty!($t2))) };