Skip to content

Commit f9f70bf

Browse files
committed
feat(norm): implement Type::from
1 parent ac8c336 commit f9f70bf

File tree

1 file changed

+23
-1
lines changed

1 file changed

+23
-1
lines changed

src/norm.rs

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,16 @@ pub enum Type {
2929

3030
impl Type {
3131
pub fn from(typ: ast::Type) -> Self {
32-
todo!()
32+
match typ {
33+
ast::Type::Int => Self::Int,
34+
ast::Type::Str => Self::Str,
35+
ast::Type::Var(var) => Self::Var(var),
36+
ast::Type::Fun(arg, ret) => Self::Fun(Box::new(Self::from(*arg)), Box::new(Self::from(*ret))),
37+
ast::Type::ForAll(pat, typ) => Self::ForAll(ForAll {
38+
pat,
39+
typ: Box::new(Self::from(*typ))
40+
})
41+
}
3342
}
3443
pub fn normalize(env: Environment, typ: Self) -> Result<face::Type> {
3544
match typ {
@@ -174,5 +183,18 @@ mod tests {
174183
let nid = face::Expr::fun(face::Type::Int, face::Expr::var(0));
175184
assert_eq!(Expr::normalize(Environment::new(), oid), Ok(nid));
176185
}
186+
187+
#[test]
188+
fn identity_apply_one() {
189+
let oid = Expr::Fun(Func {
190+
pat: "x".to_string(),
191+
typ: Type::Int,
192+
exp: Box::new(Expr::Var("x".to_string()))
193+
});
194+
let oap = Expr::App(Box::new(oid.clone()), Box::new(Expr::Int(1)));
195+
let nid = face::Expr::fun(face::Type::Int, face::Expr::var(0));
196+
let nap = face::Expr::app(nid.clone(), face::Expr::Int(1));
197+
assert_eq!(Expr::normalize(Environment::new(), oid), Ok(nid));
198+
}
177199
}
178200
}

0 commit comments

Comments
 (0)