问题
I am reading about mechanization of linear logic in Coq http://www.cs.cmu.edu/~iliano/projects/metaCLF2/inc/dl/papers/lsfa17.pdf and https://github.com/brunofx86/LL and I have trouble to understand the type constructors of the inductive type term
from https://github.com/brunofx86/LL/blob/master/FOLL/LL/SyntaxLL.v:
Inductive term :=
|var (t: T) (* variables *)
|cte (e:A) (* constants from the domain DT.A *)
|fc1 (n:nat) (t: term) (* family of functions of 1 argument *)
|fc2 (n:nat) (t1 t2: term). (* family of functions of 2 argument *)
I have two question regarding this sample (I am reading https://softwarefoundations.cis.upenn.edu/lf-current/Basics.html along this paper):
- what is the (super)type of
term
? Software Foundations always specifies the (super)type of the new type, likeInductive color : Type
; - the main question - how to understand type constructor
var (t: T)
?. Software Foundation in its first chapter provides only two types of type constructors: constantwhite : color
and functionprimary : rgb → color
. Butvar (t: T)
is very strange notation - it is not valid function type definition as it have no explicit return type and also it has no arrow.
回答1:
Regarding your main question, the syntax var (t : T)
when defining a constructor is just some alternative (shorter) syntax for var : forall t : T, term
, which can just as well be written var : T -> term
(since there is no occurrence of variable t
in term
).
Actually, you can check this by processing the definition, then the following command:
Print term.
(* and Coq displays the inductive type with the default syntax, that is:
Inductive term : Type :=
var : T -> term
| cte : A -> term
| fc1 : nat -> term -> term
| fc2 : nat -> term -> term -> term
*)
Next (as shown by the Coq output above), the type of the datatype term
is indeed Type
.
I recall that in Coq, all types have also a type, and this latter will always be Prop
, Set
or Type
. A "type of type" is usually called a sort. (The sort Prop
deals with logical propositions while the sorts Set
and Type
deal with so-called "informative" types.)
Finally, it can be noted that Type
does not refer to a fixed type, but to a given Type_i
where the index i >=0
is automatically determined and checked by Coq's kernel. For more information on this topic, see for example the first section of the Universes chapter of CPDT
来源:https://stackoverflow.com/questions/49718746/how-to-understand-coq-type-constructor-var-t-t