From a26da934f4f6a182e0e8bb24dbbd3be0162a4717 Mon Sep 17 00:00:00 2001 From: greg Date: Thu, 17 May 2018 00:48:48 -0700 Subject: [PATCH] Substitution monotypes --- schala-lang/src/typechecking.rs | 17 +++++++++++++++++ 1 file changed, 17 insertions(+) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 91db9ac..c9b31e5 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -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)]