Debian Codegraph @

test-suite/success/HintMode.v

raw
1 Module Postponing.
2
3 Class In A T := { IsIn : A -> T -> Prop }.
4 Class Empty T := { empty : T }.
5 Class EmptyIn (A T : Type) `{In A T} `{Empty T} :=
6 { isempty : forall x, IsIn x empty -> False }.
7
8 #[export] Hint Mode EmptyIn ! ! - - : typeclass_instances.
9 #[export] Hint Mode Empty ! : typeclass_instances.
10 #[export] Hint Mode In ! - : typeclass_instances.
11 Existing Class IsIn.
12 Goal forall A T `{In A T} `{Empty T} `{EmptyIn A T}, forall x : A, IsIn x empty -> False.
13 Proof.
14 intros.
15 eapply @isempty. (* Second goal needs to be solved first, to un-stuck the first one
16 (hence the Existing Class IsIn to allow finding the assumption of IsIn here) *)
17 all:typeclasses eauto.
18 Qed.
19
20 End Postponing.
21
22 Module Heads.
23 Set Primitive Projections.
24 Class A (X : Type) := { somex : X }.
25 Local Hint Mode A ! : typeclass_instances.
26
27 Record foo := { car : Type; obj : car }.
28 Local Instance foo_A (f : foo) : A (car f) := { somex := obj f }.
29
30 Definition onef := {| car := nat; obj := 0 |}.
31 Goal {f : foo & A (car f)}.
32 Proof.
33 unshelve eexists; cycle 1.
34 solve [typeclasses eauto].
35 exact onef.
36 Defined.
37 End Heads.
38
39 Module BestEffort.
40
41 Class A (T : Type).
42 Global Hint Mode A + : typeclass_instances.
43 Class B (T : Type).
44 Global Hint Mode B + : typeclass_instances.
45
46 #[export] Instance a_imp_b T : A T -> B T := {}.
47 #[export] Instance anat : B nat := {}.
48 Lemma b : B nat * A nat.
49 Proof.
50 Fail split; typeclasses eauto.
51 Set Typeclasses Debug Verbosity 2.
52 Fail split; solve [typeclasses eauto best_effort].
53 (* Here typeclasses eauto best_effort, when run on the 2 goals at once,
54 can solve the B goal which has a nat instance nd whose mode is +
55 (this morally assumes that there is only one instance matching B nat)
56 *)
57 split; typeclasses eauto best_effort.
58 admit.
59 Admitted.
60
61 End BestEffort.
62
63 Module Plus.
64 Parameter plus : nat -> nat -> nat -> Prop.
65
66 Axiom plus0l : forall m : nat, plus 0 m m.
67 Axiom plus0r : forall n : nat, plus n 0 n.
68 Axiom plusSl : forall n m r : nat, plus n m r -> plus (S n) m (S r).
69 Axiom plusSr : forall n m r : nat, plus n m r -> plus m (S m) (S r).
70
71 Hint Resolve plus0l plus0r plusSl plusSr : plus.
72 Hint Mode plus ! - - : plus.
73 Hint Mode plus - ! - : plus.
74
75 Require Corelib.derive.Derive.
76 Derive r SuchThat (plus 1 4 r) As r_proof.
77 Proof.
78 subst r. typeclasses eauto with plus.
79 Qed.
80
81 Goal exists x y, plus x y 12.
82 Proof.
83 eexists ?[x], ?[y].
84 Set Typeclasses Debug.
85 Fail typeclasses eauto with plus.
86 instantiate (y := 1).
87 typeclasses eauto with plus.
88 Defined.
89 End Plus.
90
91 Module ModeAttr.
92 Fail #[mode="+"] Inductive foo (A : Type) : Set :=.
93
94 Fail #[mode=""] Class Foo (A : Type) := {}.
95 #[mode="+"] Class Foo (A : Type) := {}.
96 Fail #[mode="+ +"] Class Foo' (A : Type) := {}.
97 End ModeAttr.