author | wenzelm |
Wed, 25 Jun 2025 16:35:25 +0200 | |
changeset 82768 | 8f866fd6fae1 |
parent 81590 | e656c5edc352 |
permissions | -rw-r--r-- |
42151 | 1 |
(* Title: HOL/HOLCF/Tools/cont_consts.ML |
81226 | 2 |
Author: Tobias Mayr |
3 |
Author: David von Oheimb |
|
4 |
Author: Makarius |
|
23152 | 5 |
|
81226 | 6 |
HOLCF version of 'consts' command: handle continuous function types in mixfix |
23152 | 7 |
syntax. |
8 |
*) |
|
9 |
||
10 |
signature CONT_CONSTS = |
|
11 |
sig |
|
35257 | 12 |
val add_consts: (binding * typ * mixfix) list -> theory -> theory |
13 |
val add_consts_cmd: (binding * string * mixfix) list -> theory -> theory |
|
40832 | 14 |
end |
23152 | 15 |
|
35257 | 16 |
structure Cont_Consts: CONT_CONSTS = |
23152 | 17 |
struct |
18 |
||
81226 | 19 |
fun count_cfun \<^Type>\<open>cfun _ B\<close> = count_cfun B + 1 |
20 |
| count_cfun _ = 0 |
|
23152 | 21 |
|
81226 | 22 |
fun change_cfun 0 T = T |
23 |
| change_cfun n \<^Type>\<open>cfun A B\<close> = \<^Type>\<open>fun A \<open>change_cfun (n - 1) B\<close>\<close> |
|
81228 | 24 |
| change_cfun _ T = raise TYPE ("cont_consts: change_cfun", [T], []) |
35257 | 25 |
|
23152 | 26 |
fun gen_add_consts prep_typ raw_decls thy = |
27 |
let |
|
81226 | 28 |
val thy_ctxt = Proof_Context.init_global thy |
29 |
||
30 |
fun is_cont_const (_, _, NoSyn) = false |
|
81228 | 31 |
| is_cont_const (_, _, Binder _) = false |
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
32 |
| is_cont_const (b, T, mx) = |
81226 | 33 |
let |
34 |
val n = Mixfix.mixfix_args thy_ctxt mx handle ERROR msg => |
|
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
35 |
cat_error msg ("in mixfix annotation for " ^ Binding.print b) |
81226 | 36 |
in count_cfun T >= n end |
37 |
||
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
38 |
fun transform (b, T, mx) = |
81226 | 39 |
let |
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
40 |
val c = Sign.full_name thy b |
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
41 |
val c1 = Lexicon.mark_syntax c |
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
42 |
val c2 = Lexicon.mark_const c |
81507 | 43 |
val xs = Name.invent_global "xa" (Mixfix.mixfix_args thy_ctxt mx) |
81228 | 44 |
val trans_rules = |
45 |
Syntax.Parse_Print_Rule |
|
46 |
(Ast.mk_appl (Ast.Constant c1) (map Ast.Variable xs), |
|
47 |
fold (fn x => fn t => |
|
48 |
Ast.mk_appl (Ast.Constant \<^const_syntax>\<open>Rep_cfun\<close>) [t, Ast.Variable x]) |
|
49 |
xs (Ast.Constant c2)) :: |
|
50 |
(if Mixfix.is_infix mx then [Syntax.Parse_Rule (Ast.Constant c1, Ast.Constant c2)] else []) |
|
51 |
in ((b, T, NoSyn), (c1, change_cfun (length xs) T, mx), trans_rules) end |
|
81226 | 52 |
|
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
53 |
val decls = map (fn (b, T, mx) => (b, prep_typ thy T, mx)) raw_decls |
81226 | 54 |
val (cont_decls, normal_decls) = List.partition is_cont_const decls |
55 |
val transformed_decls = map transform cont_decls |
|
23152 | 56 |
in |
57 |
thy |
|
81227
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
58 |
|> Sign.add_consts (normal_decls @ map #1 transformed_decls) |
2f5c1761541d
clarified concrete vs. abstract syntax: avoid translations on logical consts;
wenzelm
parents:
81226
diff
changeset
|
59 |
|> Sign.syntax_global true Syntax.mode_default (map #2 transformed_decls) |
81590 | 60 |
|> Sign.translations_global true (maps #3 transformed_decls) |
40832 | 61 |
end |
23152 | 62 |
|
40832 | 63 |
val add_consts = gen_add_consts Sign.certify_typ |
64 |
val add_consts_cmd = gen_add_consts Syntax.read_typ_global |
|
35257 | 65 |
|
40832 | 66 |
end |