+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
+;;
+
+let intro_tac name =
+ exact_tac
+ ("",0,(CicNotationPt.Binder (`Lambda,
+ (CicNotationPt.Ident (name,None),None),CicNotationPt.Implicit)))
+;;
+
+let analyse_indty status ty =
+ let ref, args =
+ match whd status (`Term ty) ty with
+ | _,_,NCic.Const ref -> ref, []
+ | _,_,NCic.Appl (NCic.Const ref :: args) -> ref, args
+ | _,_,_ -> fail (lazy ("not an inductive type")) in
+ let _,lno,tl,_,i = NCicEnvironment.get_checked_indtys ref in
+ let _,_,_,cl = List.nth tl i in
+ let consno = List.length cl in
+ let left, right = HExtlib.split_nth lno args in
+ ref, consno, left, right
+;;
+
+let case status goal =
+ let _,ctx,_ = get_goal status goal in
+ let ty = typeof status (`Ctx ctx) ("",ctx,NCic.Rel 1) in
+ let ref, consno, left, right = analyse_indty status ty in
+ let t =
+ NCic.Match (ref,NCic.Implicit `Term,NCic.Rel 1,
+ HExtlib.mk_list (NCic.Implicit `Term) consno)
+ in
+ let status,t,ty = refine status (`Ctx ctx) ("",ctx,t) None in
+ instantiate status goal t
+;;
+
+let case_tac = distribute_tac case;;
+
+let case1_tac name =
+ block_tac [ intro_tac name; case_tac ]
+;;