- let pattern =
- match fst(CicEnvironment.get_obj
- CicUniv.empty_ugraph turi ) with
- C.InductiveDefinition (ind_type_list,_,nr_ind_params_dx,_) ->
- let _,_,_,constructor_list = (List.nth ind_type_list typeno) in
- let i_constr_id,_ = List.nth constructor_list (consno - 1) in
- List.map
- (function (id,cty) ->
- let reduced_cty = CicReduction.whd context cty in
- let rec aux t k =
- match t with
- C.Prod (_,_,target) when (k <= nr_ind_params_dx) ->
- aux target (k+1)
- | C.Prod (binder,source,target) when (k > nr_ind_params_dx) ->
- let binder' =
- match binder with
- C.Name b -> C.Name b
- | C.Anonymous -> C.Name "y"
- in
- C.Lambda (binder',source,(aux target (k+1)))
- | _ ->
- let nr_param_constr = k - 1 - nr_ind_params_dx in
- if (id = i_constr_id)
- then C.Rel (nr_param_constr - i + 1)
- else S.lift (nr_param_constr + 1) t1' (* + 1 per liftare anche il lambda agguinto esternamente al case *)
- in aux reduced_cty 1
- )
- constructor_list
- | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: object is not an Inductive Definition: it's imposible"))
+ let patterns,outtype =
+ match
+ fst (CicEnvironment.get_obj CicUniv.empty_ugraph turi)
+ with
+ C.InductiveDefinition (ind_type_list,_,paramsno,_)->
+ let _,_,_,constructor_list =
+ List.nth ind_type_list typeno in
+ let i_constr_id,_ =
+ List.nth constructor_list (consno - 1) in
+ let seed = ref 0 in
+ let patterns =
+ List.map
+ (function (id,cty) ->
+ let reduced_cty = CicReduction.whd context cty in
+ let rec aux t k =
+ match t with
+ C.Prod (_,_,target) when k <= paramsno ->
+ aux target (k+1)
+ | C.Prod (binder,source,target) when k > paramsno ->
+ let binder' =
+ match binder with
+ C.Name _ -> binder
+ | C.Anonymous ->
+ C.Name
+ (incr seed; "y" ^ string_of_int !seed)
+ in
+ C.Lambda (binder',source,(aux target (k+1)))
+ | _ ->
+ let nr_param_constr = k - 1 - paramsno in
+ if id = i_constr_id
+ then C.Rel (k - i)
+ else S.lift (nr_param_constr + 1) t1' (* + 1 per liftare anche il lambda aggiunto esternamente al case *)
+ in aux reduced_cty 1
+ ) constructor_list in
+ let outtype =
+ let seed = ref 0 in
+ let rec to_lambdas te head =
+ match CicReduction.whd context te with
+ | C.Prod (binder,so,ta) ->
+ let binder' =
+ match binder with
+ C.Name _ -> binder
+ | C.Anonymous ->
+ C.Name (incr seed; "d" ^ string_of_int !seed)
+ in
+ C.Lambda (binder',so,to_lambdas ta head)
+ | _ -> head in
+ let rec skip_prods n te =
+ match n, CicReduction.whd context te with
+ 0, _ -> te
+ | n, C.Prod (_,_,ta) -> skip_prods (n - 1) ta
+ | _, _ -> assert false
+ in
+ let abstracted_tty =
+ match CicSubstitution.lift (paramsno + 1) tty with
+ C.MutInd _ as tty' -> tty'
+ | C.Appl l ->
+ let keep,abstract =
+ HExtlib.split_nth (paramsno +1) l in
+ let rec mk_rels =
+ function
+ 0 -> []
+ | n -> C.Rel n :: (mk_rels (n - 1))
+ in
+ C.Appl (keep@mk_rels (List.length abstract))
+ | _ -> assert false
+ in
+ match ind_type_list with
+ [] -> assert false
+ | (_,_,ty,_)::_ ->
+ to_lambdas (skip_prods paramsno ty)
+ (C.Lambda (C.Name "x", abstracted_tty,
+ S.lift (2+paramsno) tty'))
+ in
+ patterns,outtype
+ | _ -> raise (ProofEngineTypes.Fail (lazy "Discriminate: object is not an Inductive Definition: it's imposible"))