问题
If I have the following line:
Definition Foo : Set := list nat.
then I compile with no problems.
However, suppose I want to do the same with Coq.Lists.ListSet
, a library representing finite sets as lists:
(*Section first_definitions.
Variable A : Type.
Definition listset := list A.*)
Definition Bar : Set := listset nat.
I get the following error:
The term "listset nat" has type "Type" while it is expected to have type
"Set" (universe inconsistency).
- Is there a way to "cast"
listset
so that it lives inSet
instead ofType
? i.e. If I know I'm going to be usinglistset
with parameters of typeSet
, is there a way to make it live in theSet
heirarchy somehow? - Why does the error happen for
listset
, but not forlist
, whenlistset
is defined to belist
?
Note: The actual type is called set
, but I've renamed it to listset
to avoid confusion with the sort Set
.
EDIT: =
replaced with :=
回答1:
- Why does the error happen for listset, but not for list, when listset is defined to be list?
Because list
is a template universe polymorphic inductive definition (see About list.
), which in this case means that if list
is applied to a type in Set
, the result is still in Set
.
- Is there a way to "cast"
listset
so that it lives inSet
instead ofType
?
AFAIK, there is no way to make definitions template universe polymorphic, but you can make them universe polymorphic like so:
Polymorphic Definition listset (A : Type) : Type := list A.
Check listset nat : Set.
One more option is to use Set Universe Polymorphism
command so you won't need to prepend your definitions with the Polymorphic
keyword.
This feature has experimental status at the time of writing. And it does not apply retroactively, so I guess you would need to fork your own ListSet
.
来源:https://stackoverflow.com/questions/51277444/coq-non-list-data-structures-living-in-set