| NCic.LetIn _
| NCic.Lambda _
| NCic.Const (NReference.Ref (_,NReference.CoFix _))
- | NCic.Appl [] -> assert false (* NOT POSSIBLE *)
+ | NCic.Appl [] ->
+ assert false (* NOT POSSIBLE *)
| NCic.Match _
| NCic.Const (NReference.Ref (_,NReference.Fix _)) ->
(* be aware: we can be the head of an application *)
;;
-let context_of_typformer status ~metasenv context =
+let rev_context_of_typformer status ~metasenv context =
function
NCic.Const (NReference.Ref (_,NReference.Ind _) as ref)
| NCic.Const (NReference.Ref (_,NReference.Def _) as ref)
| NCic.Const (NReference.Ref (_,NReference.Decl) as ref)
| NCic.Const (NReference.Ref (_,NReference.Fix _) as ref) ->
- (try fst (ReferenceMap.find ref status#extraction_db)
+ (try List.rev (fst (ReferenceMap.find ref status#extraction_db))
with
Not_found ->
- prerr_endline ("REF NOT FOUND: " ^ NReference.string_of_reference ref);
- assert false (* IMPOSSIBLE *))
+ (* This can happen only when we are processing the type of
+ the constructor of a small singleton type. In this case
+ we are not interested in all the type, but only in its
+ backbone. That is why we can safely return the dummy context here *)
+ let rec dummy = None::dummy in
+ dummy)
| NCic.Match _ -> assert false (* TODO ???? *)
| NCic.Rel n ->
let typ =
| _,NCic.Def _ -> assert false (* IMPOSSIBLE *) in
let typ_ctx = snd (HExtlib.split_nth n context) in
let typ = kind_of status ~metasenv typ_ctx typ in
- fst (split_kind_prods [] typ)
+ List.rev (fst (split_kind_prods [] typ))
| NCic.Meta _ -> assert false (* TODO *)
| NCic.Const (NReference.Ref (_,NReference.Con _))
| NCic.Const (NReference.Ref (_,NReference.CoFix _))
| NCic.Rel n -> Var n
| NCic.Const ref -> TConst ref
| NCic.Appl (he::args) ->
- let he_context = context_of_typformer status ~metasenv context he in
+ let rev_he_context= rev_context_of_typformer status ~metasenv context he in
TAppl (typ_of status ~metasenv context he ::
List.map
(function None -> Unit | Some ty -> typ_of status ~metasenv context ty)
- (skip_args status ~metasenv context (List.rev he_context,args)))
+ (skip_args status ~metasenv context (rev_he_context,args)))
| NCic.Appl _ -> assert false (* TODO: when head is a match/let rec;
otherwise NOT A TYPE *)
| NCic.Meta _
| NCic.Match (_,_,_,_) -> assert false (* TODO *)
;;
+let rec fomega_lift_type_from n k =
+ function
+ | Var m as t -> if m < k then t else Var (m + n)
+ | Top -> Top
+ | TConst _ as t -> t
+ | Unit -> Unit
+ | Arrow (ty1,ty2) -> Arrow (fomega_lift_type_from n k ty1,fomega_lift_type_from n (k+1) ty2)
+ | TSkip t -> TSkip (fomega_lift_type_from n (k+1) t)
+ | Forall (name,kind,t) -> Forall (name,kind,fomega_lift_type_from n (k+1) t)
+ | TAppl args -> TAppl (List.map (fomega_lift_type_from n k) args)
+
+let fomega_lift_type n t =
+ if n = 0 then t else fomega_lift_type_from n 0 t
+
+let fomega_lift_term n t =
+ let rec fomega_lift_term n k =
+ function
+ | Rel m as t -> if m < k then t else Rel (m + n)
+ | BottomElim
+ | UnitTerm
+ | Const _ as t -> t
+ | Lambda (name,t) -> Lambda (name,fomega_lift_term n (k+1) t)
+ | TLambda (name,t) -> TLambda (name,fomega_lift_term n (k+1) t)
+ | Appl args -> Appl (List.map (fomega_lift_term n k) args)
+ | LetIn (name,m,bo) ->
+ LetIn (name, fomega_lift_term n k m, fomega_lift_term n (k+1) bo)
+ | Match (ref,t,pl) ->
+ let lift_p (ctx,t) =
+ let lift_context ctx =
+ let len = List.length ctx in
+ HExtlib.list_mapi
+ (fun el i ->
+ let j = len - i - 1 in
+ match el with
+ None
+ | Some (_,`OfKind _) as el -> el
+ | Some (name,`OfType t) ->
+ Some (name,`OfType (fomega_lift_type_from n (k+j) t))
+ ) ctx
+ in
+ lift_context ctx, fomega_lift_term n (k + List.length ctx) t
+ in
+ Match (ref,fomega_lift_term n k t,List.map lift_p pl)
+ | Inst t -> Inst (fomega_lift_term n k t)
+ | Skip t -> Skip (fomega_lift_term n (k+1) t)
+ | UnsafeCoerce t -> UnsafeCoerce (fomega_lift_term n k t)
+ in
+ if n = 0 then t else fomega_lift_term n 0 t
+;;
+
let rec fomega_subst k t1 =
function
| Var n ->
- if k=n then t1
+ if k=n then fomega_lift_type k t1
else if n < k then Var n
else Var (n-1)
| Top -> Top
let context = (name,NCic.Decl ty)::context in
eat_branch 0 t context ctx t'
| Top,_ -> assert false (*TODO: HOW??*)
- (*BUG here, eta-expand!*)
+ | TSkip _, _
+ | Forall _,_
+ | Arrow _,_ -> assert false (*BUG here, eta-expand!*)
| _, _ -> context,ctx, pat
in
try
| `Proposition ->
(match patterns_of pl with
[] -> BottomElim
- | [_lhs,rhs] -> rhs (*BUG HERE: Rels are not ok, bound in the _lhs*)
+ | [lhs,rhs] -> fomega_lift_term (- List.length lhs) rhs
| _ -> assert false)
| `Type ->
Match (ref,term_of status ~metasenv context t, patterns_of pl))
| _ -> term_of status ~metasenv context arg in
eat_args status metasenv (mk_appl acc arg) context t tl
| Forall (_,_,t) ->
- eat_args status metasenv (Inst acc)
- context (fomega_subst 1 (typ_of status ~metasenv context arg) t) tl
+ (match classify status ~metasenv context arg with
+ | `PropKind -> assert false (*TODO: same as below, coercion needed???*)
+ | `Proposition
+ | `Term `TypeFormer
+ | `Kind ->
+ eat_args status metasenv (UnsafeCoerce (Inst acc))
+ context (fomega_subst 1 Unit t) tl
+ | `Term _ -> assert false (*TODO: ????*)
+ | `KindOrType
+ | `Type ->
+ eat_args status metasenv (Inst acc)
+ context (fomega_subst 1 (typ_of status ~metasenv context arg) t)
+ tl)
| TSkip t ->
eat_args status metasenv acc context t tl
| Top -> assert false (*TODO: HOW??*)