Substitution monotypes

This commit is contained in:
greg 2018-05-17 00:48:48 -07:00
parent 1de1cd9cfd
commit a26da934f4
1 changed files with 17 additions and 0 deletions

View File

@ -77,6 +77,19 @@ impl MonoType {
},
}
}
//TODO maybe this should be type self, and consume?
fn apply_substitution(&self, s: &Substitution) -> MonoType {
use self::MonoType::*;
match self {
Const(t) => Const(t.clone()),
Var(a) => s.0.get(a).map(|x| x.clone()).unwrap_or(Var(a.clone())),
Function(a, b) => Function(
Box::new(a.apply_substitution(s)),
Box::new(b.apply_substitution(s))
)
}
}
}
#[derive(Debug, PartialEq, Clone)]
@ -87,6 +100,10 @@ impl PolyType {
let mtype = self.1.free_vars();
self.0.difference(&mtype).cloned().collect()
}
fn apply_substitution(&self, s: &Substitution) -> PolyType {
unimplemented!()
}
}
#[derive(Debug, PartialEq, Clone)]