@@ -125,7 +125,8 @@ and paths_row ta ps = function
125125let rec_from_extyp typ label s =
126126 match s with
127127 | ExT ([] , t ) ->
128- let rec find_rec = function
128+ let rec find_rec t =
129+ match follow_typ t with
129130 | AppT (t , ts ) ->
130131 let rec_t, unroll_t, roll_t, ak = find_rec t in
131132 rec_t, AppT (unroll_t, ts), AppT (roll_t, ts), ak
@@ -399,13 +400,18 @@ Trace.debug (lazy ("[FunE] env =" ^ VarSet.fold (fun a s -> s ^ " " ^ a) (domain
399400 IL. genE(erase_bind aks, IL. LamE (var.it, erase_typ t, e2))
400401
401402 | EL. WrapE (var , typ ) ->
403+ let var_t = lookup_var env var in
402404 let s, zs1 =
403405 match elab_typ env typ " " with
404406 | ExT ([] , WrapT(s )), zs1 -> s, zs1
407+ | ExT ([] , InferT(z )), zs1 ->
408+ let s = ExT ([] , var_t) in
409+ resolve_always z (WrapT (s));
410+ s, zs1
405411 | _ -> error typ.at " non-wrapped type for wrap"
406412 in
407413 let _, zs2, f =
408- try sub_extyp env (ExT ([] , lookup_var env var )) s []
414+ try sub_extyp env (ExT ([] , var_t )) s []
409415 with Sub e -> error exp.at
410416 (" wrapped type does not match annotation: " ^ Sub. string_of_error e)
411417 in
@@ -499,11 +505,18 @@ Trace.debug (lazy ("[AppE] ts = " ^ String.concat ", " (List.map string_of_norm_
499505 IL. AppE (IL. instE(ex1, List. map erase_typ ts), IL. AppE (f, IL. VarE (var2.it)))
500506
501507 | EL. UnwrapE (var , typ ) ->
508+ let t1, zs1, ex = elab_instvar env var in
502509 let aks, t, s2, zs2 =
503510 match elab_typ env typ l with
504511 | ExT ([] , WrapT(ExT(aks , t ) as s2 )), zs2 -> aks, t, s2, zs2
512+ | ExT ([] , InferT(z )), zs2 ->
513+ (match t1 with
514+ | WrapT (s2 ) ->
515+ resolve_always z t1;
516+ [] , t1, s2, zs2
517+ | _ ->
518+ error typ.at " could not infer type for unwrap" )
505519 | _ -> error typ.at " non-wrapped type for unwrap" in
506- let t1, zs1, ex = elab_instvar env var in
507520 let s1 =
508521 match t1 with
509522 | WrapT (s1 ) -> s1
@@ -519,9 +532,16 @@ Trace.debug (lazy ("[UnwrapE] s2 = " ^ string_of_norm_extyp s2));
519532 IL. AppE (f, IL. DotE (ex, " wrap" ))
520533
521534 | EL. UnrollE (var , typ ) ->
522- let s, zs1 = elab_typ env typ l in
523- let rec_t, unroll_t, roll_t, ak = rec_from_extyp typ " unrolling" s in
524535 let var_t = lookup_var env var in
536+ let s, zs1 =
537+ match elab_typ env typ l with
538+ | ExT ([] , InferT(z )), zs1 ->
539+ let s = ExT ([] , var_t) in
540+ resolve_always z var_t;
541+ s, zs1
542+ | s , zs1 ->
543+ s, zs1 in
544+ let rec_t, unroll_t, roll_t, ak = rec_from_extyp typ " unrolling" s in
525545 let _, zs2, f = try sub_typ env var_t roll_t [] with Sub e ->
526546 error var.at (" unrolled value does not match annotation:"
527547 ^ " " ^ Types. string_of_typ var_t ^ " "
0 commit comments