Debian Codegraph @

test-suite/success/Case13.v

raw
1 (* Check coercions in patterns *)
2
3 Inductive I : Set :=
4 | C1 : nat -> I
5 | C2 : I -> I.
6
7 Coercion C1 : nat >-> I.
8
9 (* Coercion at the root of pattern *)
10 Check (fun x => match x with
11 | C2 n => 0
12 | O => 0
13 | S n => n
14 end).
15
16 (* Coercion not at the root of pattern *)
17 Check (fun x => match x with
18 | C2 O => 0
19 | _ => 0
20 end).
21
22 (* Unification and coercions inside patterns *)
23 Check
24 (fun x : option nat => match x with
25 | None => 0
26 | Some O => 0
27 | _ => 0
28 end).
29
30 (* Coercion up to delta-conversion, and unification *)
31 Coercion somenat := Some (A:=nat).
32 Check (fun x => match x with
33 | None => 0
34 | O => 0
35 | S n => n
36 end).
37
38 (* Coercions with parameters *)
39 Inductive listn : nat -> Set :=
40 | niln : listn 0
41 | consn : forall n : nat, nat -> listn n -> listn (S n).
42
43 Inductive I' : nat -> Set :=
44 | C1' : forall n : nat, listn n -> I' n
45 | C2' : forall n : nat, I' n -> I' n.
46
47 Coercion C1' : listn >-> I'.
48 Check (fun x : I' 0 => match x with
49 | C2' _ _ => 0
50 | niln => 0
51 | _ => 0
52 end).
53 Check (fun x : I' 0 => match x with
54 | C2' _ niln => 0
55 | _ => 0
56 end).
57
58 (* This one could eventually be solved, the "Fail" is just to ensure *)
59 (* that it does not fail with an anomaly, as it did at some time *)
60 Fail Check (fun x : I' 0 => match x return _ x with
61 | C2' _ _ => 0
62 | niln => 0
63 | _ => 0
64 end).
65
66 (* Check insertion of coercions around matched subterm *)
67
68 Parameter A:Set.
69 Parameter f:> A -> nat.
70
71 Inductive J : Set := D : A -> J.
72
73 Check (fun x => match x with
74 | D 0 => 0
75 | D _ => 1
76 end).
77
78 (* Check coercions against the type of the term to match *)
79 (* Used to fail in V8.1beta *)
80
81 Inductive C : Set := c : C.
82 Inductive E : Set := e :> C -> E.
83 Check fun (x : E) => match x with c => e c end.
84
85 (* Check coercions with uniform parameters (cf bug #1168) *)
86
87 Inductive C' : bool -> Set := c' : C' true.
88 Inductive E' (b : bool) : Set := e' :> C' b -> E' b.
89 Check fun (x : E' true) => match x with c' => e' true c' end.
90
91 (* Check use of the no-dependency strategy when a type constraint is
92 given (and when the "inversion-and-dependencies-as-evars" strategy
93 is not strong enough because of a constructor with a type whose
94 pattern structure is not refined enough for it to be captured by
95 the inversion predicate) *)
96
97 Inductive K : bool -> bool -> Type := F : K true true | G x : K x x.
98
99 Check fun z P Q (y:K true z) (H1 H2:P y) (f:forall y, P y -> Q y z) =>
100 match y with
101 | F => f y H1
102 | G _ => f y H2
103 end : Q y z.
104
105 (* Check use of the maximal-dependency-in-variable strategy even when
106 no explicit type constraint is given (and when the
107 "inversion-and-dependencies-as-evars" strategy is not strong enough
108 because of a constructor with a type whose pattern structure is not
109 refined enough for it to be captured by the inversion predicate) *)
110
111 Check fun z P Q (y:K true z) (H1 H2:P y) (f:forall y z, P y -> Q y z) =>
112 match y with
113 | F => f y true H1
114 | G b => f y b H2
115 end.
116
117 (* Check use of the maximal-dependency-in-variable strategy for "Var"
118 variables *)
119
120 Goal forall z P Q (y:K true z) (H1 H2:P y) (f:forall y z, P y -> Q y z), Q y z.
121 intros z P Q y H1 H2 f.
122 Show.
123 refine (match y with
124 | F => f y true H1
125 | G b => f y b H2
126 end).
127 Qed.