fact: Definition destruct {A : Type} (n : A) : tactic := fun g => let A := reduce (RedWhd [rl:RedBeta]) A in b <- M.is_var n; ctx <- if b then M.hyps_except n else M.hyps; match g in goal gs return match gs with gs_any => True | gs_open => M (mlist (unit *m goal gs_any)) end with | Metavar s gT _ => P <- M.Cevar (A->s) ctx; let Pn := P n in M.unify_or_fail UniCoq Pn gT;; '(mkInd_dyn _ _ _ l as i) <- M.constrs A; l <- apply_params_to_constructors (Dyn A) i; l <- M.map (fun d : dyn => t' <- copy_ctx P d; e <- M.Cevar t' ctx; M.ret (Dyn e)) l; let c := {| case_ind := A; case_val := n; case_return := Dyn P; case_branches := l |} in case <- M.makecase c; dcase case as e in exact e g;; M.map (fun d => '(Metavar _ _ g) <- M.dyn_to_goal d; M.ret (m: tt, AnyMetavar _ _ g)) l | _ => I end.
imports: Strings.String ssrmatching.ssrmatching Mtac2(Logic Datatypes List Utils Logic Sorts MTeleMatch) Strings.String NArith.BinNat NArith.BinNatDef