fresh
This commit is contained in:
parent
4017857a3a
commit
c96a56a7ac
@ -260,7 +260,7 @@ impl TypeContext {
|
|||||||
|
|
||||||
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<String> {
|
pub fn type_check_ast(&mut self, ast: &parsing::AST) -> TypeResult<String> {
|
||||||
let ref block = ast.0;
|
let ref block = ast.0;
|
||||||
let mut infer = Infer::new();
|
let mut infer = Infer::default();
|
||||||
let output = infer.infer_block(block);
|
let output = infer.infer_block(block);
|
||||||
match output {
|
match output {
|
||||||
Ok(s) => Ok(format!("{:?}", s)),
|
Ok(s) => Ok(format!("{:?}", s)),
|
||||||
@ -270,9 +270,9 @@ impl TypeContext {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// this is the equivalent of the Haskell Infer monad
|
// this is the equivalent of the Haskell Infer monad
|
||||||
#[derive(Debug)]
|
#[derive(Debug, Default)]
|
||||||
struct Infer {
|
struct Infer {
|
||||||
|
_idents: u32,
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug)]
|
#[derive(Debug)]
|
||||||
@ -283,8 +283,11 @@ enum InferError {
|
|||||||
}
|
}
|
||||||
|
|
||||||
impl Infer {
|
impl Infer {
|
||||||
fn new() -> Infer {
|
fn fresh(&mut self) -> MonoType {
|
||||||
Infer { }
|
let i = self._idents;
|
||||||
|
self._idents += 1;
|
||||||
|
let name = Rc::new(format!("{}", ('a' as u8 + 1) as char));
|
||||||
|
MonoType::Var(name)
|
||||||
}
|
}
|
||||||
|
|
||||||
fn infer_block(&mut self, block: &Vec<parsing::Statement>) -> Result<MonoType, InferError> {
|
fn infer_block(&mut self, block: &Vec<parsing::Statement>) -> Result<MonoType, InferError> {
|
||||||
|
Loading…
Reference in New Issue
Block a user