@@ -29,7 +29,16 @@ pub enum Type {
29
29
30
30
impl Type {
31
31
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
+ }
33
42
}
34
43
pub fn normalize ( env : Environment , typ : Self ) -> Result < face:: Type > {
35
44
match typ {
@@ -174,5 +183,18 @@ mod tests {
174
183
let nid = face:: Expr :: fun ( face:: Type :: Int , face:: Expr :: var ( 0 ) ) ;
175
184
assert_eq ! ( Expr :: normalize( Environment :: new( ) , oid) , Ok ( nid) ) ;
176
185
}
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
+ }
177
199
}
178
200
}
0 commit comments