coq-club AT inria.fr
Subject: The Coq mailing list
List archive
- From: Cedric Auger <sedrikov AT gmail.com>
- To: "coq-club AT inria.fr" <coq-club AT inria.fr>
- Subject: Re: [Coq-Club] are type indexes ever necessary?
- Date: Tue, 22 Mar 2016 19:37:20 +0100
- Authentication-results: mail2-smtp-roc.national.inria.fr; spf=None smtp.pra=sedrikov AT gmail.com; spf=Pass smtp.mailfrom=sedrikov AT gmail.com; spf=None smtp.helo=postmaster AT mail-ig0-f179.google.com
- Ironport-phdr: 9a23:Bk+qnRBSKBBDPmgJSRRCUyQJP3N1i/DPJgcQr6AfoPdwSP7+r8bcNUDSrc9gkEXOFd2CrakU26yP7+u5ADFIyK3CmU5BWaQEbwUCh8QSkl5oK+++Imq/EsTXaTcnFt9JTl5v8iLzG0FUHMHjew+a+SXqvnYsExnyfTB4Ov7yUtaLyZ/nh6brp9aKOlgArQH+SI0xBS3+lR/WuMgSjNkqAYcK4TyNnEF1ff9Lz3hjP1OZkkW0zM6x+Jl+73YY4Kp5pIYTGZn9Ku4zSqUdBzA7OUg04tfqvF/NV0HHsnAbSyAdlgdCKwnD9hDzGJnr5HjUrO14jQKXMdf3RvgdRDuv9e8/UxLkkiYEMCAR/2Tei8g2h6Ve9kHy7ydjypLZNdnGfMF1ebnQKIsX
2016-03-21 20:03 GMT+01:00 Jonathan Leivent <jonikelee AT gmail.com>:
Is it true in Coq that any index on an inductive type could *always* be replaced by a type parameter with an extra equality-typed field added to each constructor tying the type parameter to that constructor's value for it?
Except of course for the type eq itself, which needs a type index (because of course one can't define eq using an eq-typed field to replace the index).
For example, fin:
Inductive fin : nat -> Set :=
| Fin1(n : nat) : fin (S n)
| FinS(n : nat) : fin n -> fin (S n).
could be redefined as:
Inductive fin(m : nat) : Set :=
| Fin1(n : nat)(_: m = S n)
| FinS(n : nat)(_: fin n)(_: m = S n).
I think it is always the case. One cannot prove it directly in Coq as we would have to use "meta"functions taking a type as argument, and inspect its construction to build an other one which would be isomorphic.
I keep revisiting this because of various difficulties that type indexes create - such as the need for the inversion tactic, and the corresponding convoy patterns in Gallina match expressions. Also, some tactics, such as case_eq, tend to misbehave when the type has indexes. But, is the claim really true? If not, what is an example where a type index cannot be adequately replaced by a parameter/equality combo?
If such an example exist (and I doubt of it, although I have no strong proof of it), I guess it must be so uncommon, that your approach should apply in all practical cases.
Defining an inductive type with indexes that vary among the constructors causes case analysis (elimination, destruction, induction) of instances of that type to induce some change to the environment in which the case analysis occurs. If that inductive type is defined with type parameters and equality fields instead, then case analysis does not by itself induce any environment change - that's left for the equality fields - which can then be used only as needed. Hence, there is a better separation of concerns.
There is the extra tedium of always having to fill in the constructors' new equality fields with arguments - but writing "eq_refl" a few times takes no brain power (and could perhaps be automated). Similarly, the equality fields might accumulate in proof mode. But tactics like subst and congruence make that manageable.
-- Jonathan
Now I tend to avoid that kind of annoyance with an other approach:
Inductive finS(X:Set) : Set :=
| Fin1
| FinS : X -> finS X.
Fixpoint fin(m:nat) : Set :=
match m with
| O => emptySet
| S n => finS (fin m)
end.
I find this kind of type quite convenient to use. "inversion f." becomes "destruct n; destruct f." with no weirdness to deal with.
Induction is done on the parameter rather than the type, and all basic operation have their counterparts in a not too artificial way.
I find it nice to have the ability to "reduce" the type to only those which are possible in a given context.
I am conscious on the fact that such a transcription of type is not always trivially existent, but in many cases, there is a strong relation between the constructor of the type and the constructors of the index, leading to a natural way to make it.
Cases which do not apply still, are those where the index is not a constructed type (and I don’t pretend this to be the only case).
Example: Inductive is_identity {A:Type} : (A->A)->Prop := Id : is_identity (fun x => x).
Example: Inductive is_identity {A:Type} : (A->A)->Prop := Id : is_identity (fun x => x).
- [Coq-Club] are type indexes ever necessary?, Jonathan Leivent, 03/21/2016
- Re: [Coq-Club] are type indexes ever necessary?, Cedric Auger, 03/22/2016
- Re: [Coq-Club] are type indexes ever necessary?, Jonathan Leivent, 03/23/2016
- Re: [Coq-Club] are type indexes ever necessary?, Matthieu Sozeau, 03/25/2016
- Re: [Coq-Club] are type indexes ever necessary?, Jonathan Leivent, 03/23/2016
- Re: [Coq-Club] are type indexes ever necessary?, Cedric Auger, 03/22/2016
Archive powered by MHonArc 2.6.18.