module C = NCic
module R = NReference
+let head_beta_reduce = ref (fun ~upto:_ _ -> assert false);;
+let set_head_beta_reduce = (:=) head_beta_reduce;;
+
let r2s pp_fix_name r =
try
match r with
F.fprintf f "]@] @]";
| C.Appl [] | C.Appl [_] | C.Appl (C.Appl _::_) ->
F.fprintf f "BAD APPLICATION"
+ | C.Appl (C.Meta (n,lc) :: args) when List.mem_assoc n subst ->
+ let _,_,t,_ = List.assoc n subst in
+ let hd = NCicSubstitution.subst_meta lc t in
+ aux ctx
+ (!head_beta_reduce ~upto:(List.length args)
+ (match hd with
+ | NCic.Appl l -> NCic.Appl (l@args)
+ | _ -> NCic.Appl (hd :: args)))
| C.Appl l ->
F.fprintf f "@[<hov 2>";
if not toplevel then F.fprintf f "(";
(e.g. the tactic could perform a global analysis of the set of goals)
*)
-let exec tac (low_status,g) =
+let exec tac low_status g =
let stack = [ [0,Open g], [], [], `NoTag ] in
let status = tac { gstatus = stack ; istatus = low_status } in
status.istatus
mk_meta status ~name:out_scope_tag (`Ctx context) (`Def term)
;;
+let select ~where status goal =
+ let name, _, _ as goalty = get_goal status goal in
+ let (wanted,_,where) = GrafiteDisambiguate.disambiguate_npattern where in
+ let path =
+ match where with None -> NCic.Implicit `Term | Some where -> where
+ in
+ let status, newgoalty = select_term status goalty (wanted,path) in
+ let status, instance =
+ mk_meta status ?name (`Term newgoalty) (`Decl newgoalty)
+ in
+ instantiate status goal instance
+;;
+
+let select_tac ~where = distribute_tac (select ~where) ;;
let exact t status goal =
let goalty = get_goal status goal in
instantiate status goal t
;;
-
let reopen status =
let n,h,metasenv,subst,o = status.pstatus in
let subst, newm =
instantiate status goal instance
;;
-let apply t status goal =
- let uri,height,metasenv, subst,obj = status.pstatus in
- let name,context,gty = List.assoc goal metasenv in
- let metasenv, subst, lexicon_status, t =
- GrafiteDisambiguate.disambiguate_nterm (Some gty)
- status.lstatus context metasenv subst t
- in
- let subst, metasenv =
- (goal, (name, context, t, gty)):: subst,
- List.filter(fun (x,_) -> x <> goal) metasenv
- in
- let new_pstatus = uri,height,metasenv,subst,obj in
- { lstatus = lexicon_status; pstatus = new_pstatus }
-;;
+let apply t status goal = exact t status goal;;
let apply_tac t = distribute_tac (apply t) ;;
let change_tac ~where ~with_what = distribute_tac (change ~where ~with_what) ;;
+let elim_tac ~what ~where status =
+ block_tac
+ [ select_tac ~where;
+ distribute_tac (fun status goal ->
+ let goalty = get_goal status goal in
+ let status, (_,_,w as what) =
+ disambiguate status what None (`Term goalty) in
+ let _ty_what = typeof status (`Term what) what in
+ (* check inductive... find eliminator *)
+ let w = (*astify what *) CicNotationPt.Ident ("m",None) in
+ let holes = [
+ CicNotationPt.Implicit;CicNotationPt.Implicit;CicNotationPt.Implicit]
+ in
+ let eliminator =
+ CicNotationPt.Appl(CicNotationPt.Ident("nat_ind",None)::holes @ [ w ])
+ in
+ exec (apply_tac ("",0,eliminator)) status goal) ]
+ status
+;;
+
+