Debian Codegraph @

test-suite/success/reverse_coercions_ac.v

raw
1 Set Implicit Arguments.
2
3 Class Inhab (A:Type) : Prop :=
4 { inhab: exists (x:A), True }.
5
6 Record IType : Type := IType_make
7 { IType_type :> Type;
8 IType_inhab : Inhab IType_type }.
9
10 Canonical default_IType t ct : IType := @IType_make t ct.
11
12 Arguments IType_make IType_type {IType_inhab}.
13
14 Global Instance Inhab_IType : forall (A:IType), Inhab A.
15 Proof using. constructor. apply IType_inhab. Defined.
16
17 Parameter P : Type -> Prop.
18
19 (** A [IType] can be provided where an type [A] with a proof of [Inhab A] is expected. *)
20 Parameter K : forall (A:Type) (IA:Inhab A), P A.
21 Lemma testK : forall (A:IType), P A.
22 Proof using. intros. eapply K. eauto with typeclass_instances. Qed.
23
24 (** A type [A] can be provided where a [IType] is expected, by wrapping it with [IType_make]. *)
25 Parameter T : forall (A:IType), P A.
26 Lemma testT : forall (A:Type) (IA:Inhab A), P A.
27 Proof using. intros. eapply (T A). Qed.
28
29 (* Above, it would be nice to write [eapply (T A)], or just [eapply T].
30 For that, we'd need to coerce [A:Type] to the type [IType]
31 by applying on-the-fly the operation [IType_make A _]. Thus, we need something like:
32 [Coercion (fun (A:Type) => IType_make A _) : Sortclass >-> IType.]
33 Would that be possible?
34
35 I understand that [IType_type] is already a reverse coercion from [IType] to [Type],
36 but I don't see why it would necessarily cause trouble to have cycles
37 in the coercion graphs. *)