%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%% coq-arg-HOAS %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % This section contains the low level data types linking Coq and elpi. % In particular the entry points for commands % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Entry points % % Command and tactic invocation % %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% % Entry point for commands. Eg. "#[att=true] Elpi mycommand foo 3 (f x)." becomes % main [str "foo", int 3, trm (app[f,x])] % in a context where % attributes [attribute "att" (leaf "true")] % holds. The encoding of terms is described below. % See also the coq.parse-attributes utility. external pred main i:list argument. % Commands with a non-trivial parsing phase can thread data between % from the parsing phase to the interp one in an untyped way using the % following two entrypoints external pred main-interp i:list argument, i:any. external pred main-synterp i:list argument, o:any. % Commands starting/closing proofs have to use the following entrypoints. % The minimal working snippet is: % % main-interp-proof [trm P] _ P GL _ :- % coq.typecheck P _ ok, coq.ltac.collect-goals P GL _. % main-interp-qed _ _ P _GL _ :- % coq.env.add-const "it" P _ _ _. % % Where GL are the goals to prove, and _GL (unused here) are the same goals % with their current proof. The term P can be used as the root proof term, % where GL are missing pieces. One is not obliged to use P as is, i.e. he % can inspect _GL and declare each proof independenlty, or combine these proofs % as he likes and ignore P completely. When a main-interp-qed is used to end % a proof stated by a standard Rocq Lemma/Definition statement, the data from % the proof opening command is the lemma name, _GL is the empty list and P the % proof term. external pred main-interp-proof i:list argument, % arguments passed to the command i:any, % data from the parsing phase (defaults to _) o:term, % proof data for the corresponding proof-closing command o:list sealed-goal, % the sequents to prove o:any. % any data for the corresponding proof-closing command external pred main-interp-qed i:list argument, % arguments passed to the command i:any, % data from the parsing phase (defaults to _) i:term, % proof data from the corresponding proof-opening command i:list sealed-goal, % the sequents from the corresponding proof-opening command, but with proofs i:any. % any data from the corresponding proof-opening command pred usage. external func attributes -> list attribute. % see coq-lib.elpi for coq.parse-attributes generating the options below external pred get-option o:string, o:A. % The data type of arguments (for commands or tactics) kind argument type. external symbol int : int -> argument. % Eg. 1 -2. external symbol str : string -> argument. % Eg. x "y" z.w. or any Coq keyword/symbol external symbol trm : term -> argument. % Eg. (t). external symbol open-trm : int -> term -> argument. % Extra arguments for commands. [Definition], [Axiom], [Record] and [Context] % take precedence over the [str] argument above (when not "quoted"). % % Eg. Record or Inductive external symbol indt-decl : indt-decl -> argument. % Eg. #[universes(polymorphic,...)] Record or Inductive external symbol upoly-indt-decl : indt-decl -> upoly-decl -> argument. % Eg. Definition or Axiom (when the body is none) external symbol const-decl : id -> option term -> arity -> argument. % Eg. #[universes(polymorphic,...)] Definition or Axiom external symbol upoly-const-decl : id -> option term -> arity -> upoly-decl -> argument. % Eg. Context A (b : A). external symbol ctx-decl : context-decl -> argument. % Declaration of inductive types %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%% kind indt-decl type. kind indc-decl type. kind record-decl type. % An arity is written, in Coq syntax, as: % (x : T1) .. (xn : Tn) : S1 -> ... -> Sn -> U % This syntax is used, for example, in the type of an inductive type or % in the type of constructors. We call the abstractions on the left of ":" % "parameters" while we call the type following the ":" (proper) arity. % Note: in some contexts, like the type of an inductive type constructor, % Coq makes no distinction between these two writings % (xn : Tn) : forall y1 : S1, ... and (xn : Tn) (y1 : S1) : ... % while Elpi is a bit more restrictive, since it understands user directives % such as the implicit status of an arguments (eg, using {} instead of () around % the binder), only on parameters. % Moreover parameters carry the name given by the user as an "id", while binders % in terms only carry it as a "name", an irrelevant pretty pringintg hint (see % also the HOAS of terms). A user command can hence only use the names of % parameters, and not the names of "forall" quantified variables in the arity. % % See also the arity->term predicate in coq-lib.elpi kind arity type. external symbol parameter : id -> implicit_kind -> term -> (term -> arity) -> arity = "1". external symbol arity : term -> arity. external symbol parameter : id -> implicit_kind -> term -> (term -> indt-decl) -> indt-decl = "2". external symbol inductive : id -> bool -> arity -> (term -> list indc-decl) -> indt-decl. % tt means inductive, ff coinductive external symbol minductive : id -> bool -> arity -> (term -> indt-decl) -> indt-decl. % one type of a mutual block external symbol mblock : list (list indc-decl) -> indt-decl. % constructor blocks for minductive declarations external symbol record : id -> term -> id -> record-decl -> indt-decl. external symbol constructor : id -> arity -> indc-decl. external symbol field : field-attributes -> id -> term -> (term -> record-decl) -> record-decl. external symbol end-record : record-decl. % Example. % Remark that A is a regular parameter; y is a non-uniform parameter and t % also features an index of type bool. % % Inductive t (A : Type) | (y : nat) : bool -> Type := % | K1 (x : A) {n : nat} : S n = y -> t A n true -> t A y true % | K2 : t A y false % % is written % % (parameter "A" explicit {{ Type }} a\ % inductive "t" tt (parameter "y" explicit {{ nat }} _\ % arity {{ bool -> Type }}) % t\ % [ constructor "K1" % (parameter "y" explicit {{ nat }} y\ % (parameter "x" explicit a x\ % (parameter "n" maximal {{ nat }} n\ % arity {{ S lp:n = lp:y -> lp:t lp:n true -> lp:t lp:y true }}))) % , constructor "K2" % (parameter "y" explicit {{ nat }} y\ % arity {{ lp:t lp:y false }}) ]) % % Remark that the uniform parameters are not passed to occurrences of t, since % they never change, while non-uniform parameters are both abstracted % in each constructor type and passed as arguments to t. % % The coq.typecheck-indt-decl API can be used to fill in implicit arguments % an infer universe constraints in the declaration above (e.g. the hidden % argument of "=" in the arity of K1). % % Note: when and inductive type declaration is passed as an argument to an % Elpi command non uniform parameters must be separated from the uniform ones % with a | (a syntax introduced in Coq 8.12 and accepted by rocq-elpi since % version 1.4, in Coq this separator is optional, but not in Elpi). % Context declaration (used as an argument to Elpi commands) kind context-decl type. % Eg. (x : T) or (x := B), body is optional, type may be a variable external symbol context-item : id -> implicit_kind -> term -> option term -> (term -> context-decl) -> context-decl. external symbol context-end : context-decl. typeabbrev field-attributes (list field-attribute). macro @global! :- get-option "coq:locality" "global". macro @local! :- get-option "coq:locality" "local".