author | haftmann |
Fri, 02 Jul 2010 14:23:17 +0200 | |
changeset 37692 | 7b072f0c8bde |
parent 37459 | 7a3610dca96b |
child 38857 | 97775f3e8722 |
permissions | -rw-r--r-- |
24999 | 1 |
(* Title: HOL/Library/Code_Char.thy |
2 |
Author: Florian Haftmann |
|
3 |
*) |
|
4 |
||
5 |
header {* Code generation of pretty characters (and strings) *} |
|
6 |
||
7 |
theory Code_Char |
|
32657 | 8 |
imports List Code_Evaluation Main |
24999 | 9 |
begin |
10 |
||
11 |
code_type char |
|
12 |
(SML "char") |
|
13 |
(OCaml "char") |
|
14 |
(Haskell "Char") |
|
37222 | 15 |
(Scala "Char") |
24999 | 16 |
|
17 |
setup {* |
|
37222 | 18 |
fold String_Code.add_literal_char ["SML", "OCaml", "Haskell", "Scala"] |
31053 | 19 |
#> String_Code.add_literal_list_string "Haskell" |
24999 | 20 |
*} |
21 |
||
22 |
code_instance char :: eq |
|
23 |
(Haskell -) |
|
24 |
||
25 |
code_reserved SML |
|
26 |
char |
|
27 |
||
28 |
code_reserved OCaml |
|
29 |
char |
|
30 |
||
37222 | 31 |
code_reserved Scala |
32 |
char |
|
33 |
||
28346
b8390cd56b8f
discontinued special treatment of op = vs. eq_class.eq
haftmann
parents:
28244
diff
changeset
|
34 |
code_const "eq_class.eq \<Colon> char \<Rightarrow> char \<Rightarrow> bool" |
24999 | 35 |
(SML "!((_ : char) = _)") |
36 |
(OCaml "!((_ : char) = _)") |
|
37 |
(Haskell infixl 4 "==") |
|
37222 | 38 |
(Scala infixl 5 "==") |
24999 | 39 |
|
32657 | 40 |
code_const "Code_Evaluation.term_of \<Colon> char \<Rightarrow> term" |
31046 | 41 |
(Eval "HOLogic.mk'_char/ (IntInf.fromInt/ (Char.ord/ _))") |
28228 | 42 |
|
33234 | 43 |
|
44 |
definition implode :: "string \<Rightarrow> String.literal" where |
|
45 |
"implode = STR" |
|
46 |
||
47 |
primrec explode :: "String.literal \<Rightarrow> string" where |
|
48 |
"explode (STR s) = s" |
|
49 |
||
50 |
lemma [code]: |
|
51 |
"literal_case f s = f (explode s)" |
|
52 |
"literal_rec f s = f (explode s)" |
|
53 |
by (cases s, simp)+ |
|
54 |
||
55 |
code_reserved SML String |
|
56 |
||
57 |
code_const implode |
|
58 |
(SML "String.implode") |
|
59 |
(OCaml "failwith/ \"implode\"") |
|
60 |
(Haskell "_") |
|
37459 | 61 |
(Scala "!(\"\" ++/ _)") |
33234 | 62 |
|
63 |
code_const explode |
|
64 |
(SML "String.explode") |
|
65 |
(OCaml "failwith/ \"explode\"") |
|
66 |
(Haskell "_") |
|
37459 | 67 |
(Scala "!(_.toList)") |
33234 | 68 |
|
24999 | 69 |
end |