有没有办法在环境中的Universe中显示类型或所有类型的所有术语?
Print Set. (*Syntax error: 'Firstorder' 'Solver' expected after 'Print' (in [vernac:command]).*)
答案 0 :(得分:3)
您可以使用搜索来获得近似值。你可以这样做:
Search $Type.
并获取类型为$Type
的结果。例如,
Search nat -(forall _, _).
将显示nat
类型的所有字词。
Search Set -(forall _, _).
将显示Set
类型的所有非功能性术语。
SearchPattern
应该提供类似的功能,但我不确定。 Ssreflect搜索可以做到这一点以及更多。
答案 1 :(得分:2)
如果环境是指证明环境,则以下用户定义的策略可以做到这一点。
Ltac printInType t :=
match goal with
| [ H : t |- _ ] =>
idtac H; fail
| _ => idtac
end
.
Theorem test : forall n m, n + m = m + n.
Proof.
intros.
printInType nat.
(* prints in the Message window:
m
n
*)
printInType Set.
(* prints nothing
because nat for instance is not explicitely in the proof environment *)
它所做的正是通过证明环境并找到具有参数类型t
的假设或变量。 idtac H
打印它,然后分支由于fail
策略而失败。现在,Coq在不同的假设/变量上再次尝试相同的分支,因此所有这样的假设/变量最终都被打印出来。现在,第二个分支| _ => idtac
只是为了确保策略最终成功。如果没有这个分支,策略将失败并出现错误,并且在打印错误时,Coq将删除之前打印的信息。
答案 2 :(得分:1)
不,Coq中没有这样的功能。 Print
仅显示给定术语的正文,例如:
Print plus.
plus =
fix plus (n m : nat) {struct n} : nat :=
match n with
| 0 => m
| S p => S (plus p m)
end
: nat -> nat -> nat
Argument scopes are [nat_scope nat_scope]