Move type-level func up
This commit is contained in:
parent
f79dc0b1e3
commit
4534c1d3d6
@ -24,6 +24,7 @@ use schala_lang::parsing::{AST, Statement, Declaration, Signature, Expression, E
|
|||||||
pub enum Type {
|
pub enum Type {
|
||||||
TVar(TypeVar),
|
TVar(TypeVar),
|
||||||
TConst(TypeConst),
|
TConst(TypeConst),
|
||||||
|
TFunc(Box<Type>, Box<Type>),
|
||||||
}
|
}
|
||||||
|
|
||||||
#[derive(Debug, PartialEq, Clone)]
|
#[derive(Debug, PartialEq, Clone)]
|
||||||
@ -45,7 +46,6 @@ pub enum TypeConst {
|
|||||||
StringT,
|
StringT,
|
||||||
Boolean,
|
Boolean,
|
||||||
Unit,
|
Unit,
|
||||||
FunctionT(Box<Type>, Box<Type>),
|
|
||||||
Bottom,
|
Bottom,
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -97,10 +97,7 @@ impl TypeContext {
|
|||||||
let arg = args.get(0).unwrap();
|
let arg = args.get(0).unwrap();
|
||||||
let type_arg = self.from_anno(arg);
|
let type_arg = self.from_anno(arg);
|
||||||
let spec = PathSpecifier(data_construcor.clone());
|
let spec = PathSpecifier(data_construcor.clone());
|
||||||
let ty = TConst(FunctionT(
|
let ty = TFunc(Box::new(type_arg), Box::new(TConst(UserT(type_constructor.clone()))));
|
||||||
Box::new(type_arg),
|
|
||||||
Box::new(TConst(UserT(type_constructor.clone()))),
|
|
||||||
));
|
|
||||||
(spec, ty)
|
(spec, ty)
|
||||||
|
|
||||||
},
|
},
|
||||||
@ -181,12 +178,12 @@ impl TypeContext {
|
|||||||
|
|
||||||
let return_type = sig.type_anno.as_ref().map(|anno| self.from_anno(&anno)).unwrap_or_else(|| { get_type() });
|
let return_type = sig.type_anno.as_ref().map(|anno| self.from_anno(&anno)).unwrap_or_else(|| { get_type() });
|
||||||
if sig.params.len() == 0 {
|
if sig.params.len() == 0 {
|
||||||
TConst(FunctionT(Box::new(TConst(Unit)), Box::new(return_type)))
|
TFunc(Box::new(TConst(Unit)), Box::new(return_type))
|
||||||
} else {
|
} else {
|
||||||
let mut output_type = return_type;
|
let mut output_type = return_type;
|
||||||
for p in sig.params.iter() {
|
for p in sig.params.iter() {
|
||||||
let p_type = p.1.as_ref().map(|anno| self.from_anno(anno)).unwrap_or_else(|| { get_type() });
|
let p_type = p.1.as_ref().map(|anno| self.from_anno(anno)).unwrap_or_else(|| { get_type() });
|
||||||
output_type = TConst(FunctionT(Box::new(p_type), Box::new(output_type)));
|
output_type = TFunc(Box::new(p_type), Box::new(output_type));
|
||||||
}
|
}
|
||||||
output_type
|
output_type
|
||||||
}
|
}
|
||||||
@ -331,7 +328,7 @@ impl TypeContext {
|
|||||||
let tf = self.infer(f)?;
|
let tf = self.infer(f)?;
|
||||||
let targ = self.infer(arguments.get(0).unwrap())?;
|
let targ = self.infer(arguments.get(0).unwrap())?;
|
||||||
match tf {
|
match tf {
|
||||||
TConst(FunctionT(box t1, box t2)) => {
|
TFunc(box t1, box t2) => {
|
||||||
let _ = self.unify(t1, targ);
|
let _ = self.unify(t1, targ);
|
||||||
t2
|
t2
|
||||||
},
|
},
|
||||||
|
Loading…
Reference in New Issue
Block a user