Module Proofview
This files defines the basic mechanism of proofs: the proofview type is the state which tactics manipulate (a global state for existential variables, together with the list of goals), and the type 'a tactic is the (abstract) type of tactics modifying the proof state and returning a value of type 'a.
val proofview : proofview -> Evar.t list * Evd.evar_mapReturns a stylised view of a proofview for use by, for instance, ide-s.
Starting and querying a proof view
val init : Evd.evar_map -> (Environ.env * EConstr.types) list -> entry * proofviewInitialises a proofview, the main argument is a list of environments (including a
named_contextwhich are used as hypotheses) pair with conclusion types, creating accordingly many initial goals. Because a proof does not necessarily starts in an emptyevar_map(indeed a proof can be triggered by an incomplete pretyping),inittakes an additional argument to represent the initialevar_map.
type telescope=|TNil of Evd.evar_map|TCons of Environ.env * Evd.evar_map * EConstr.types * Evd.evar_map -> EConstr.constr -> telescopeA
telescopeis a list of environment and conclusion like ininit, except that each element may depend on the previous goals. The telescope passes the goals in the form of aTerm.constrwhich represents the goal as anevar. Theevar_mapis threaded in state passing style.
val dependent_init : telescope -> entry * proofviewLike
init, but goals are allowed to be dependent on one another. Dependencies between goals is represented with the typetelescopeinstead oflist. Note that the firstevar_mapof the telescope plays the role of theevar_mapargument ininit.
val finished : proofview -> boolfinished pvistrueif and only ifpvis complete. That is, if it has an empty list of focused goals. There could still be unsolved subgoals, but they would then be out of focus.
val return : proofview -> Evd.evar_mapReturns the current
evarstate.
val partial_proof : entry -> proofview -> EConstr.constr listval initial_goals : entry -> (EConstr.constr * EConstr.types) list
val with_empty_state : Proofview_monad.goal -> Proofview_monad.goal_with_stateval drop_state : Proofview_monad.goal_with_state -> Proofview_monad.goalval goal_with_state : Proofview_monad.goal -> Proofview_monad.StateStore.t -> Proofview_monad.goal_with_state
Focusing commands
type focus_contextA
focus_contextrepresents the part of the proof view which has been removed by a focusing action, it can be used to unfocus later on.
val focus_context : focus_context -> Evar.t list * Evar.t listReturns a stylised view of a focus_context for use by, for instance, ide-s.
val focus : int -> int -> proofview -> proofview * focus_contextfocus i jfocuses a proofview on the goals from indexito indexj(inclusive, goals are indexed from1). I.e. goals numberitojbecome the only focused goals of the returned proofview. It returns the focused proofview, and a context for the focus stack.
val unfocus : focus_context -> proofview -> proofviewUnfocuses a proofview with respect to a context.
The tactic monad
val apply : name:Names.Id.t -> poly:bool -> Environ.env -> 'a tactic -> proofview -> 'a * proofview * (bool * Evar.t list * Evar.t list) * Proofview_monad.Info.treeApplies a tactic to the current proofview. Returns a tuple
a,pv,(b,sh,gu)whereais the return value of the tactic,pvis the updated proofview,ba boolean which istrueif the tactic has not done any action considered unsafe (such as admitting a lemma),shis the list of goals which have been shelved by the tactic, andguthe list of goals on which the tactic has given up. In case of multiple success the first one is selected. If there is no success, fails withLogic_monad.TacticFailure
Monadic primitives
val tclUNIT : 'a -> 'a tacticUnit of the tactic monad.
val tclTHEN : unit tactic -> 'a tactic -> 'a tacticInterprets the ";" (semicolon) of Ltac. As a monadic operation, it's a specialized "bind".
Failure and backtracking
val tclZERO : ?info:Exninfo.info -> exn -> 'a tactictclZERO efails with exceptione. It has no success. Exception is supposed to be non critical
val tclOR : 'a tactic -> (Exninfo.iexn -> 'a tactic) -> 'a tactictclOR t1 t2behaves liket1as long ast1succeeds. Whenever the successes oft1have been depleted and it failed withe, then it behaves ast2 e. In other words,tclORinserts a backtracking point. Int2, exception can be assumed non critical.
val tclORELSE : 'a tactic -> (Exninfo.iexn -> 'a tactic) -> 'a tactictclORELSE t1 t2is equal tot1ift1has at least one success ort2 eift1fails withe. It is analogous totry/withhandler of exception in that it is not a backtracking point. Int2, exception can be assumed non critical.
val tclIFCATCH : 'a tactic -> ('a -> 'b tactic) -> (Exninfo.iexn -> 'b tactic) -> 'b tactictclIFCATCH a s fis a generalisation oftclORELSE: ifasucceeds at least once then it behaves astclBIND a sotherwise, ifafails withe, then it behaves asf e. Infexception can be assumed non critical.
val tclONCE : 'a tactic -> 'a tactictclONCE tbehave liketexcept it has at most one success:tclONCE tstops after the first success oft. Iftfails withe,tclONCE talso fails withe.
exceptionMoreThanOneSuccesstclEXACTLY_ONCE e tsucceeds astifthas exactly one success. Otherwise it fails. The tactictis run until its first success, then a failure with exceptioneis simulated (ehas to be non critical). Iftyields another success, thentclEXACTLY_ONCE e tfails withMoreThanOneSuccess(it is a user error). Otherwise,tclEXACTLY_ONCE e tsucceeds with the first success oft. Notice that the choice ofeis relevant, as the presence of further successes may depend one(seetclOR).
type 'a case=|Fail of Exninfo.iexn|Next of 'a * Exninfo.iexn -> 'a tactictclCASE tsplitstinto its first success and a continuation. It is the most general primitive to control backtracking.
val tclCASE : 'a tactic -> 'a case tacticval tclBREAK : (Exninfo.iexn -> Exninfo.iexn option) -> 'a tactic -> 'a tactictclBREAK p tis a generalization oftclONCE t. Instead of stopping after the first success, it succeeds liketuntil a failure with an exceptionesuch thatp e = Some e'is raised. At which point it drops the remaining successes, failing withe'.tclONCE tis equivalent totclBREAK (fun e -> Some e) t.
Focusing tactics
exceptionNoSuchGoals of inttclFOCUS i j tappliestafter focusing on the goals numberitoj(seefocus). The rest of the goals is restored after the tactic action. If the specified range doesn't correspond to existing goals, fails with thenosuchgoalargument, by default raisingNoSuchGoals(a user error). This exception is caught at toplevel with a default message.
val tclFOCUS : ?nosuchgoal:'a tactic -> int -> int -> 'a tactic -> 'a tacticval tclFOCUSLIST : ?nosuchgoal:'a tactic -> (int * int) list -> 'a tactic -> 'a tactictclFOCUSLIST li tapplieston the list of focused goals described byli. Each element ofliis a pair(i, j)denoting the goals numbered fromitoj(inclusive, starting from 1). It will try to applytto all the valid goals in any of these intervals. If the set of such goals is not a single range, then it will move goals such that it is a single range. (So, for instance,[1, 3-5]; idtac.is not the identity.) If the set of such goals is empty, it will fail withnosuchgoal, by default raisingNoSuchGoals 0.
val tclFOCUSID : ?nosuchgoal:'a tactic -> Names.Id.t -> 'a tactic -> 'a tactictclFOCUSID x tapplieston a (single) focused goal liketclFOCUS. The goal is found by its name rather than its number. Fails withnosuchgoal, by default raisingNoSuchGoals 1.
Dispatching on goals
exceptionSizeMismatch of int * intDispatch tacticals are used to apply a different tactic to each goal under focus. They come in two flavours:
tclDISPATCHtakes a list ofunit tactic-s and build aunit tactic.tclDISPATCHLtakes a list of'a tacticand returns an'a list tactic.They both work by applying each of the tactic in a focus restricted to the corresponding goal (starting with the first goal). In the case of
tclDISPATCHL, the tactic returns a list of the same size as the argument list (of tactics), each element being the result of the tactic executed in the corresponding goal.When the length of the tactic list is not the number of goal, raises
SizeMismatch (g,t)wheregis the number of available goals, andtthe number of tactics passed.
val tclDISPATCH : unit tactic list -> unit tacticval tclDISPATCHL : 'a tactic list -> 'a list tacticval tclEXTEND : unit tactic list -> unit tactic -> unit tactic list -> unit tactictclEXTEND b r eis a variant oftclDISPATCH, where thertactic is "repeated" enough time such that every goal has a tactic assigned to it (bis the list of tactics applied to the first goals,eto the last goals, andris applied to every goal in between).
Goal manipulation
val shelve : unit tacticShelves all the goals under focus. The goals are placed on the shelf for later use (or being solved by side-effects).
val shelve_goals : Evar.t list -> unit tacticShelves the given list of goals, which might include some that are under focus and some that aren't. All the goals are placed on the shelf for later use (or being solved by side-effects).
val unifiable : Evd.evar_map -> Evar.t -> Evar.t list -> boolunifiable sigma g lchecks whethergappears in another subgoal ofl. The listlmay containg, but it does not affect the result. Used byshelve_unifiable.
val shelve_unifiable : unit tacticShelves the unifiable goals under focus, i.e. the goals which appear in other goals under focus (the unfocused goals are not considered).
val shelve_unifiable_informative : Evar.t list tacticIdem but also returns the list of shelved variables
val guard_no_unifiable : Names.Name.t list option tacticguard_no_unifiablereturns the list of unifiable goals if some goals are unifiable (seeshelve_unifiable) in the current focus.
val unshelve : Evar.t list -> proofview -> proofviewunshelve l padds all the goals inlat the end of the focused goals of p
val depends_on : Evd.evar_map -> Evar.t -> Evar.t -> booldepends_on g1 g2 sigmachecks if g1 occurs in the type/ctx of g2
val with_shelf : 'a tactic -> (Evar.t list * 'a) tacticwith_shelf tacexecutestacand returns its result together with the set of goals shelved bytac. The current shelf is unchanged and the returned list contains only unsolved goals.
val cycle : int -> unit tacticIf
nis positive,cycle nputs thenfirst goal last. Ifnis negative, then it puts thenlast goals first.
val swap : int -> int -> unit tacticswap i jswaps the position of goals numberiandj(negative numbers can be used to address goals from the end. Goals are indexed from1. For simplicity index0corresponds to goal1as well, rather than raising an error.
val revgoals : unit tacticrevgoalsreverses the list of focused goals.
val numgoals : int tacticnumgoalsreturns the number of goals under focus.
Access primitives
val tclEVARMAP : Evd.evar_map tactictclEVARMAPdoesn't affect the proof, it returns the currentevar_map.
val tclENV : Environ.env tactictclENVdoesn't affect the proof, it returns the current environment. It is not the environment of a particular goal, rather the "global" environment of the proof. The goal-wise environment is obtained viaProofview.Goal.env.
Put-like primitives
val tclEFFECTS : Evd.side_effects -> unit tactictclEFFECTS effadd the effectseffto the current state.
val mark_as_unsafe : unit tacticmark_as_unsafedeclares the current tactic is unsafe.
val give_up : unit tacticGives up on the goal under focus. Reports an unsafe status. Proofs with given up goals cannot be closed.
Control primitives
val tclPROGRESS : 'a tactic -> 'a tactictclPROGRESS tchecks the state of the proof aftert. It it is identical to the state before, thentclPROGRESS tfails, otherwise it succeeds liket.
module Progress : sig ... endval tclCHECKINTERRUPT : unit tacticChecks for interrupts
val tclTIMEOUT : int -> 'a tactic -> 'a tactictclTIMEOUT n tcan have only one success. In case of timeout if fails withtclZERO Timeout.
val tclTIME : string option -> 'a tactic -> 'a tactictclTIME s tdisplays time for each atomic call to t, using s as an identifying annotation if present
val tclProofInfo : (Names.Id.t * bool) tacticInternal, don't use.
Unsafe primitives
module Unsafe : sig ... endThe primitives in the
Unsafemodule should be avoided as much as possible, since they can make the proof state inconsistent. They are nevertheless helpful, in particular when interfacing the pretyping and the proof engine.
module UnsafeRepr : sig ... endThis module gives access to the innards of the monad. Its use is restricted to very specific cases.
Goal-dependent tactics
module Goal : sig ... endTrace
module Trace : sig ... endNon-logical state
module NonLogical : module type of Logic_monad.NonLogicalThe
NonLogicalmodule allows the execution of effects (including I/O) in tactics (non-logical side-effects are not discarded at failures).
val tclLIFT : 'a NonLogical.t -> 'a tactictclLIFT cis a tactic which behaves exactly asc.