it works? use boolean unifcation in normal unification

This commit is contained in:
Folkert 2020-01-07 19:17:12 +01:00
parent 2b7a20bd23
commit 99aaa31bdc
6 changed files with 23 additions and 4 deletions

View file

@ -2,6 +2,7 @@ use crate::can::ident::{Lowercase, ModuleName, Uppercase};
use crate::collections::{MutMap, MutSet};
use crate::subs::{Content, FlatType, Subs, Variable};
use crate::types::{self, name_type_var};
use crate::uniqueness::boolean_algebra::Bool;
static WILDCARD: &str = "*";
static EMPTY_RECORD: &str = "{}";
@ -300,7 +301,10 @@ fn write_flat_type(flat_type: FlatType, subs: &mut Subs, buf: &mut String, paren
}
}
}
Boolean(_) => panic!("pretty print type"),
Boolean(Bool::Variable(var)) => write_content(subs.get(var).content, subs, buf, parens),
Boolean(b) => {
buf.push_str(&format!("{:?}", b));
}
Erroneous(problem) => {
buf.push_str(&format!("<Type Mismatch: {:?}>", problem));
}

View file

@ -402,7 +402,7 @@ fn type_to_variable(
register(subs, rank, pools, content)
}
Boolean(Bool::Variable(var)) => *var,
// Boolean(Bool::Variable(var)) => *var,
Boolean(b) => {
let content = Content::Structure(FlatType::Boolean(b.clone()));

View file

@ -771,7 +771,7 @@ fn flat_type_to_err_type(subs: &mut Subs, state: &mut NameState, flat_type: Flat
}
}
Boolean(_) => panic!("TODO make error type"),
Boolean(b) => ErrorType::Boolean(b),
Erroneous(_) => ErrorType::Error,
}

View file

@ -393,6 +393,7 @@ pub enum ErrorType {
Vec<(Lowercase, ErrorType)>,
Box<ErrorType>,
),
Boolean(boolean_algebra::Bool),
Error,
}

View file

@ -5,6 +5,7 @@ use crate::subs::Content::{self, *};
use crate::subs::{Descriptor, FlatType, Mark, OptVariable, Subs, Variable};
use crate::types::RecordFieldLabel;
use crate::types::{Mismatch, Problem};
use crate::uniqueness::boolean_algebra;
type Pool = Vec<Variable>;
@ -404,6 +405,18 @@ fn unify_flat_type(
unify_tag_union(subs, pool, ctx, union1, union2)
}
(Boolean(b1), Boolean(b2)) => {
if let Some(substitution) = boolean_algebra::try_unify(b1.clone(), b2.clone()) {
for (var, replacement) in substitution {
subs.set_content(var, Structure(FlatType::Boolean(replacement)));
}
vec![]
} else {
mismatch()
}
}
(
Apply {
module_name: l_module_name,

View file

@ -5,6 +5,7 @@ use crate::types::Constraint::{self, *};
use crate::types::Expected::{self, *};
use crate::types::Type::{self, *};
use crate::types::{self, LetConstraint, Reason};
use crate::uniqueness::boolean_algebra::Bool;
pub fn exists(flex_vars: Vec<Variable>, constraint: Constraint) -> Constraint {
Constraint::Let(Box::new(LetConstraint {
@ -18,7 +19,7 @@ pub fn exists(flex_vars: Vec<Variable>, constraint: Constraint) -> Constraint {
pub fn lift(var_store: &VarStore, typ: Type) -> Type {
let uniq_var = var_store.fresh();
let uniq_type = Variable(uniq_var);
let uniq_type = Type::Boolean(Bool::Variable(uniq_var));
attr_type(uniq_type, typ)
}