From df76e7c120e2c9874c9f8ff6d25e9908a12b524f Mon Sep 17 00:00:00 2001 From: greg Date: Sun, 3 Jun 2018 23:25:22 -0700 Subject: [PATCH] Pretty-print type table --- schala-lang/src/typechecking.rs | 18 ++++++++++++++---- 1 file changed, 14 insertions(+), 4 deletions(-) diff --git a/schala-lang/src/typechecking.rs b/schala-lang/src/typechecking.rs index 5dfcff1..24022d4 100644 --- a/schala-lang/src/typechecking.rs +++ b/schala-lang/src/typechecking.rs @@ -1,11 +1,11 @@ use std::cell::RefCell; use std::rc::Rc; -use std::collections::{HashSet, HashMap}; +use std::collections::HashMap; +use std::fmt; +use std::fmt::Write; /* use std::collections::hash_set::Union; use std::iter::Iterator; -use std::fmt; -use std::fmt::Write; use itertools::Itertools; */ @@ -37,6 +37,12 @@ struct Scheme { ty: Type, } +impl fmt::Display for Scheme { + fn fmt(&self, f: &mut fmt::Formatter) -> fmt::Result { + write!(f, "∀{:?} . {:?}", self.names, self.ty) + } +} + #[derive(Debug, PartialEq, Clone)] struct Substitution(HashMap); impl Substitution { @@ -85,7 +91,11 @@ impl<'a> TypeContext<'a> { } pub fn debug_types(&self) -> String { - format!("{:?}", self.global_env) + let mut output = format!("Type environment\n"); + for (name, scheme) in &self.global_env.0 { + write!(output, "{} -> {}\n", name, scheme).unwrap(); + } + output } pub fn type_check_ast(&mut self, input: &parsing::AST) -> Result {