Mercurial > urweb
comparison src/coq/Syntax.v @ 615:3c77133afd9a
Start of Featherweight Ur semantics
author | Adam Chlipala <adamc@hcoop.net> |
---|---|
date | Tue, 17 Feb 2009 14:49:28 -0500 |
parents | |
children | d26d1f3acfd6 |
comparison
equal
deleted
inserted
replaced
614:5891f47d7cff | 615:3c77133afd9a |
---|---|
1 (* Copyright (c) 2009, Adam Chlipala | |
2 * All rights reserved. | |
3 * | |
4 * Redistribution and use in source and binary forms, with or without | |
5 * modification, are permitted provided that the following conditions are met: | |
6 * | |
7 * - Redistributions of source code must retain the above copyright notice, | |
8 * this list of conditions and the following disclaimer. | |
9 * - Redistributions in binary form must reproduce the above copyright notice, | |
10 * this list of conditions and the following disclaimer in the documentation | |
11 * and/or other materials provided with the distribution. | |
12 * - The names of contributors may not be used to endorse or promote products | |
13 * derived from this software without specific prior written permission. | |
14 * | |
15 * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | |
16 * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
17 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
18 * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | |
19 * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | |
20 * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | |
21 * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | |
22 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN | |
23 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) | |
24 * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE | |
25 * POSSIBILITY OF SUCH DAMAGE. | |
26 *) | |
27 | |
28 Set Implicit Arguments. | |
29 | |
30 | |
31 Definition name := nat. | |
32 | |
33 | |
34 (** Syntax of Featherweight Ur *) | |
35 | |
36 Inductive kind : Type := | |
37 | KType : kind | |
38 | KName : kind | |
39 | KArrow : kind -> kind -> kind | |
40 | KRecord : kind -> kind. | |
41 | |
42 Section vars. | |
43 Variable cvar : kind -> Type. | |
44 | |
45 Inductive con : kind -> Type := | |
46 | CVar : forall k, cvar k -> con k | |
47 | Arrow : con KType -> con KType -> con KType | |
48 | Poly : forall k, (cvar k -> con KType) -> con KType | |
49 | CAbs : forall k1 k2, (cvar k1 -> con k2) -> con (KArrow k1 k2) | |
50 | CApp : forall k1 k2, con (KArrow k1 k2) -> con k1 -> con k2 | |
51 | Name : name -> con KName | |
52 | TRecord : con (KRecord KType) -> con KType | |
53 | CEmpty : forall k, con (KRecord k) | |
54 | CSingle : forall k, con KName -> con k -> con (KRecord k) | |
55 | CConcat : forall k, con (KRecord k) -> con (KRecord k) -> con (KRecord k) | |
56 | CFold : forall k1 k2, con (KArrow (KArrow KName (KArrow k1 (KArrow k2 k2))) | |
57 (KArrow k2 (KArrow (KRecord k1) k2))) | |
58 | CGuarded : forall k1 k2, con (KRecord k1) -> con (KRecord k1) -> con k2 -> con k2. | |
59 | |
60 Variable dvar : forall k, con (KRecord k) -> con (KRecord k) -> Type. | |
61 | |
62 Section subs. | |
63 Variable k1 : kind. | |
64 Variable c1 : con k1. | |
65 | |
66 Inductive subs : forall k2, (cvar k1 -> con k2) -> con k2 -> Type := | |
67 | S_Unchanged : forall k2 (c2 : con k2), | |
68 subs (fun _ => c2) c2 | |
69 | S_CVar : subs (fun x => CVar x) c1 | |
70 | S_Arrow : forall c2 c3 c2' c3', | |
71 subs c2 c2' | |
72 -> subs c3 c3' | |
73 -> subs (fun x => Arrow (c2 x) (c3 x)) (Arrow c2' c3') | |
74 | S_Poly : forall k (c2 : cvar k1 -> cvar k -> _) (c2' : cvar k -> _), | |
75 (forall x', subs (fun x => c2 x x') (c2' x')) | |
76 -> subs (fun x => Poly (c2 x)) (Poly c2') | |
77 | S_CAbs : forall k2 k3 (c2 : cvar k1 -> cvar k2 -> con k3) (c2' : cvar k2 -> _), | |
78 (forall x', subs (fun x => c2 x x') (c2' x')) | |
79 -> subs (fun x => CAbs (c2 x)) (CAbs c2') | |
80 | S_CApp : forall k1 k2 (c2 : _ -> con (KArrow k1 k2)) c3 c2' c3', | |
81 subs c2 c2' | |
82 -> subs c3 c3' | |
83 -> subs (fun x => CApp (c2 x) (c3 x)) (CApp c2' c3') | |
84 | S_TRecord : forall c2 c2', | |
85 subs c2 c2' | |
86 -> subs (fun x => TRecord (c2 x)) (TRecord c2') | |
87 | S_CSingle : forall k2 c2 (c3 : _ -> con k2) c2' c3', | |
88 subs c2 c2' | |
89 -> subs c3 c3' | |
90 -> subs (fun x => CSingle (c2 x) (c3 x)) (CSingle c2' c3') | |
91 | S_CConcat : forall k2 (c2 c3 : _ -> con (KRecord k2)) c2' c3', | |
92 subs c2 c2' | |
93 -> subs c3 c3' | |
94 -> subs (fun x => CConcat (c2 x) (c3 x)) (CConcat c2' c3') | |
95 | S_CGuarded : forall k2 k3 (c2 c3 : _ -> con (KRecord k2)) (c4 : _ -> con k3) c2' c3' c4', | |
96 subs c2 c2' | |
97 -> subs c3 c3' | |
98 -> subs c4 c4' | |
99 -> subs (fun x => CGuarded (c2 x) (c3 x) (c4 x)) (CGuarded c2' c3' c4'). | |
100 End subs. | |
101 | |
102 Inductive disj : forall k, con (KRecord k) -> con (KRecord k) -> Prop := | |
103 | DVar : forall k (c1 c2 : con (KRecord k)), | |
104 dvar c1 c2 -> disj c1 c2 | |
105 | DComm : forall k (c1 c2 : con (KRecord k)), | |
106 disj c1 c2 -> disj c2 c1 | |
107 | |
108 | DEmpty : forall k c2, | |
109 disj (CEmpty k) c2 | |
110 | DSingleKeys : forall k X1 X2 (c1 c2 : con k), | |
111 X1 <> X2 | |
112 -> disj (CSingle (Name X1) c1) (CSingle (Name X2) c2) | |
113 | DSingleValues : forall k n1 n2 (c1 c2 : con k) k' (c1' c2' : con k'), | |
114 disj (CSingle n1 c1') (CSingle n2 c2') | |
115 -> disj (CSingle n1 c1) (CSingle n2 c2) | |
116 | |
117 | DConcat : forall k (c1 c2 c : con (KRecord k)), | |
118 disj c1 c | |
119 -> disj c2 c | |
120 -> disj (CConcat c1 c2) c | |
121 | |
122 | DEq : forall k (c1 c2 c1' : con (KRecord k)), | |
123 disj c1 c2 | |
124 -> deq c1 c1' | |
125 -> disj c1' c2 | |
126 | |
127 with deq : forall k, con k -> con k -> Prop := | |
128 | Eq_Beta : forall k1 k2 (c1 : cvar k1 -> con k2) c2 c1', | |
129 subs c2 c1 c1' | |
130 -> deq (CApp (CAbs c1) c2) c1' | |
131 | Eq_Refl : forall k (c : con k), | |
132 deq c c | |
133 | Eq_Comm : forall k (c1 c2 : con k), | |
134 deq c2 c1 | |
135 -> deq c1 c2 | |
136 | Eq_Trans : forall k (c1 c2 c3 : con k), | |
137 deq c1 c2 | |
138 -> deq c2 c3 | |
139 -> deq c1 c3 | |
140 | Eq_Cong : forall k1 k2 c1 c1' (c2 : cvar k1 -> con k2) c2' c2'', | |
141 deq c1 c1' | |
142 -> subs c1 c2 c2' | |
143 -> subs c1' c2 c2'' | |
144 -> deq c2' c2'' | |
145 | |
146 | Eq_Concat_Empty : forall k c, | |
147 deq (CConcat (CEmpty k) c) c | |
148 | Eq_Concat_Comm : forall k (c1 c2 : con (KRecord k)), | |
149 deq (CConcat c1 c2) (CConcat c2 c1) | |
150 | Eq_Concat_Assoc : forall k (c1 c2 c3 : con (KRecord k)), | |
151 deq (CConcat c1 (CConcat c2 c3)) (CConcat (CConcat c1 c2) c3) | |
152 | |
153 | Eq_Fold_Empty : forall k1 k2 f i, | |
154 deq (CApp (CApp (CApp (CFold k1 k2) f) i) (CEmpty _)) i | |
155 | Eq_Fold_Cons : forall k1 k2 f i c1 c2 c3, | |
156 deq (CApp (CApp (CApp (CFold k1 k2) f) i) (CConcat (CSingle c1 c2) c3)) | |
157 (CApp (CApp (CApp f c1) c2) (CApp (CApp (CApp (CFold k1 k2) f) i) c3)) | |
158 | |
159 | Eq_Guarded : forall k1 k2 (c1 c2 : con (KRecord k1)) (c : con k2), | |
160 disj c1 c2 | |
161 -> deq (CGuarded c1 c2 c) c | |
162 | |
163 | Eq_Map_Ident : forall k c, | |
164 deq (CApp (CApp (CApp (CFold k (KRecord k)) | |
165 (CAbs (fun x1 => CAbs (fun x2 => CAbs (fun x3 => CConcat (CSingle (CVar x1) (CVar x2)) (CVar x3)))))) | |
166 (CEmpty _)) c) c | |
167 | Eq_Map_Dist : forall k1 k2 f c1 c2, | |
168 deq (CApp (CApp (CApp (CFold k1 (KRecord k2)) | |
169 (CAbs (fun x1 => CAbs (fun x2 => CAbs (fun x3 => CConcat (CSingle (CVar x1) (CApp f (CVar x2))) (CVar x3)))))) | |
170 (CEmpty _)) (CConcat c1 c2)) | |
171 (CConcat | |
172 (CApp (CApp (CApp (CFold k1 (KRecord k2)) | |
173 (CAbs (fun x1 => CAbs (fun x2 => CAbs (fun x3 => CConcat (CSingle (CVar x1) (CApp f (CVar x2))) (CVar x3)))))) | |
174 (CEmpty _)) c1) | |
175 (CApp (CApp (CApp (CFold k1 (KRecord k2)) | |
176 (CAbs (fun x1 => CAbs (fun x2 => CAbs (fun x3 => CConcat (CSingle (CVar x1) (CApp f (CVar x2))) (CVar x3)))))) | |
177 (CEmpty _)) c2)) | |
178 | |
179 | Eq_Fold_Fuse : forall k1 k2 k3 f i f' c, | |
180 deq (CApp (CApp (CApp (CFold k1 k2) f) i) | |
181 (CApp (CApp (CApp (CFold k3 (KRecord k1)) | |
182 (CAbs (fun x1 => CAbs (fun x2 => CAbs (fun x3 => CConcat (CSingle (CVar x1) (CApp f' (CVar x2))) (CVar x3)))))) | |
183 (CEmpty _)) c)) | |
184 (CApp (CApp (CApp (CFold k3 k2) | |
185 (CAbs (fun x1 => CAbs (fun x2 => CApp (CApp f (CVar x1)) (CApp f' (CVar x2)))))) | |
186 i) c). | |
187 | |
188 Inductive wf : forall k, con k -> Type := | |
189 | HK_CVar : forall k (x : cvar k), | |
190 wf (CVar x) | |
191 | HK_Arrow : forall c1 c2, | |
192 wf c1 -> wf c2 -> wf (Arrow c1 c2) | |
193 | HK_Poly : forall k (c1 : cvar k -> _), | |
194 (forall x, wf (c1 x)) -> wf (Poly c1) | |
195 | HK_CAbs : forall k1 k2 (c1 : cvar k1 -> con k2), | |
196 (forall x, wf (c1 x)) -> wf (CAbs c1) | |
197 | HK_CApp : forall k1 k2 (c1 : con (KArrow k1 k2)) c2, | |
198 wf c1 -> wf c2 -> wf (CApp c1 c2) | |
199 | HK_Name : forall X, | |
200 wf (Name X) | |
201 | HK_TRecord : forall c, | |
202 wf c -> wf (TRecord c) | |
203 | HK_CEmpty : forall k, | |
204 wf (CEmpty k) | |
205 | HK_CSingle : forall k c1 (c2 : con k), | |
206 wf c1 -> wf c2 -> wf (CSingle c1 c2) | |
207 | HK_CConcat : forall k (c1 c2 : con (KRecord k)), | |
208 wf c2 -> wf c2 -> disj c1 c2 -> wf (CConcat c1 c2) | |
209 | HK_CFold : forall k1 k2, | |
210 wf (CFold k1 k2) | |
211 | HK_CGuarded : forall k1 k2 (c1 c2 : con (KRecord k1)) (c : con k2), | |
212 wf c1 -> wf c2 -> (disj c1 c2 -> wf c) -> wf (CGuarded c1 c2 c). | |
213 End vars. |