Pretty-print type table
This commit is contained in:
parent
889610f0b0
commit
df76e7c120
@ -1,11 +1,11 @@
|
|||||||
use std::cell::RefCell;
|
use std::cell::RefCell;
|
||||||
use std::rc::Rc;
|
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::collections::hash_set::Union;
|
||||||
use std::iter::Iterator;
|
use std::iter::Iterator;
|
||||||
use std::fmt;
|
|
||||||
use std::fmt::Write;
|
|
||||||
use itertools::Itertools;
|
use itertools::Itertools;
|
||||||
*/
|
*/
|
||||||
|
|
||||||
@ -37,6 +37,12 @@ struct Scheme {
|
|||||||
ty: Type,
|
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)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
struct Substitution(HashMap<TypeName, Type>);
|
struct Substitution(HashMap<TypeName, Type>);
|
||||||
impl Substitution {
|
impl Substitution {
|
||||||
@ -85,7 +91,11 @@ impl<'a> TypeContext<'a> {
|
|||||||
}
|
}
|
||||||
|
|
||||||
pub fn debug_types(&self) -> String {
|
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<String, String> {
|
pub fn type_check_ast(&mut self, input: &parsing::AST) -> Result<String, String> {
|
||||||
|
Loading…
Reference in New Issue
Block a user