9 sig |
9 sig |
10 val eta_contract: bool ref |
10 val eta_contract: bool ref |
11 val mk_binder_tr: string * string -> string * (term list -> term) |
11 val mk_binder_tr: string * string -> string * (term list -> term) |
12 val mk_binder_tr': string * string -> string * (term list -> term) |
12 val mk_binder_tr': string * string -> string * (term list -> term) |
13 val dependent_tr': string * string -> term list -> term |
13 val dependent_tr': string * string -> term list -> term |
|
14 val quote_antiquote_tr: string -> string -> string -> string * (term list -> term) |
|
15 val quote_antiquote_tr': string -> string -> string -> string * (term list -> term) |
14 val mark_bound: string -> term |
16 val mark_bound: string -> term |
15 val mark_boundT: string * typ -> term |
17 val mark_boundT: string * typ -> term |
16 val variant_abs': string * typ * term -> string * term |
18 val variant_abs': string * typ * term -> string * term |
17 end; |
19 end; |
18 |
20 |
122 fun type_tr (*"_TYPE"*) [ty] = |
124 fun type_tr (*"_TYPE"*) [ty] = |
123 const constrainC $ const "TYPE" $ (const "itself" $ ty) |
125 const constrainC $ const "TYPE" $ (const "itself" $ ty) |
124 | type_tr (*"_TYPE"*) ts = raise TERM ("type_tr", ts); |
126 | type_tr (*"_TYPE"*) ts = raise TERM ("type_tr", ts); |
125 |
127 |
126 |
128 |
|
129 (* quote / antiquote *) |
|
130 |
|
131 fun quote_antiquote_tr quoteN antiquoteN name = |
|
132 let |
|
133 fun antiquote_tr i ((a as Const (c, _)) $ t) = |
|
134 if c = antiquoteN then t $ Bound i |
|
135 else a $ antiquote_tr i t |
|
136 | antiquote_tr i (t $ u) = antiquote_tr i t $ antiquote_tr i u |
|
137 | antiquote_tr i (Abs (x, T, t)) = Abs (x, T, antiquote_tr (i + 1) t) |
|
138 | antiquote_tr _ a = a; |
|
139 |
|
140 fun quote_tr [t] = const name $ Abs ("uu", dummyT, antiquote_tr 0 (incr_boundvars 1 t)) |
|
141 | quote_tr ts = raise TERM ("quote_tr", ts); |
|
142 in (quoteN, quote_tr) end; |
|
143 |
|
144 |
|
145 |
127 (** print (ast) translations **) |
146 (** print (ast) translations **) |
128 |
147 |
129 (* application *) |
148 (* application *) |
130 |
149 |
131 fun appl_ast_tr' (f, []) = raise AST ("appl_ast_tr'", [f]) |
150 fun appl_ast_tr' (f, []) = raise AST ("appl_ast_tr'", [f]) |
164 fun eta_abs (Abs (a, T, t)) = |
183 fun eta_abs (Abs (a, T, t)) = |
165 (case eta_abs t of |
184 (case eta_abs t of |
166 t' as f $ u => |
185 t' as f $ u => |
167 (case eta_abs u of |
186 (case eta_abs u of |
168 Bound 0 => |
187 Bound 0 => |
169 if 0 mem loose_bnos f orelse is_aprop f then Abs (a, T, t') |
188 if Term.loose_bvar1 (f, 0) orelse is_aprop f then Abs (a, T, t') |
170 else incr_boundvars ~1 f |
189 else incr_boundvars ~1 f |
171 | _ => Abs (a, T, t')) |
190 | _ => Abs (a, T, t')) |
172 | t' => Abs (a, T, t')) |
191 | t' => Abs (a, T, t')) |
173 | eta_abs t = t; |
192 | eta_abs t = t; |
174 in |
193 in |
273 let val x' = variant (add_term_names (B, [])) x in |
292 let val x' = variant (add_term_names (B, [])) x in |
274 (x', subst_bound (mark_boundT (x', T), B)) |
293 (x', subst_bound (mark_boundT (x', T), B)) |
275 end; |
294 end; |
276 |
295 |
277 fun dependent_tr' (q, r) (A :: Abs (x, T, B) :: ts) = |
296 fun dependent_tr' (q, r) (A :: Abs (x, T, B) :: ts) = |
278 if 0 mem (loose_bnos B) then |
297 if Term.loose_bvar1 (B, 0) then |
279 let val (x', B') = variant_abs' (x, dummyT, B); |
298 let val (x', B') = variant_abs' (x, dummyT, B); |
280 in list_comb (const q $ mark_boundT (x', T) $ A $ B', ts) end |
299 in list_comb (const q $ mark_boundT (x', T) $ A $ B', ts) end |
281 else list_comb (const r $ A $ B, ts) |
300 else list_comb (const r $ A $ B, ts) |
282 | dependent_tr' _ _ = raise Match; |
301 | dependent_tr' _ _ = raise Match; |
|
302 |
|
303 |
|
304 (* quote / antiquote *) |
|
305 |
|
306 fun no_loose_bvar i t = |
|
307 if Term.loose_bvar1 (t, i) then raise Match else t; |
|
308 |
|
309 fun quote_antiquote_tr' quoteN antiquoteN name = |
|
310 let |
|
311 fun antiquote_tr' i (t $ u) = |
|
312 if u = Bound i then const antiquoteN $ no_loose_bvar i t |
|
313 else antiquote_tr' i t $ antiquote_tr' i u |
|
314 | antiquote_tr' i (Abs (x, T, t)) = Abs (x, T, antiquote_tr' (i + 1) t) |
|
315 | antiquote_tr' i a = no_loose_bvar i a; |
|
316 |
|
317 fun quote_tr' (Abs (x, T, t) :: ts) = |
|
318 Term.list_comb (const quoteN $ incr_boundvars ~1 (antiquote_tr' 0 t), ts) |
|
319 | quote_tr' _ = raise Match; |
|
320 in (name, quote_tr') end; |
283 |
321 |
284 |
322 |
285 |
323 |
286 (** pure_trfuns **) |
324 (** pure_trfuns **) |
287 |
325 |