Add more infrastructure for unify

This commit is contained in:
greg 2019-02-23 00:59:58 -08:00
parent 00a0de4431
commit be175a2b75
1 changed files with 5 additions and 3 deletions

View File

@ -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<TypeConst>;
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))) };