src/HOL/Library/Code_Char.thy
changeset 52435 6646bb548c6b
parent 51542 738598beeb26
child 54596 368c70ee1f46
--- a/src/HOL/Library/Code_Char.thy	Sun Jun 23 21:16:06 2013 +0200
+++ b/src/HOL/Library/Code_Char.thy	Sun Jun 23 21:16:07 2013 +0200
@@ -8,19 +8,28 @@
 imports Main Char_ord
 begin
 
-code_type char
-  (SML "char")
-  (OCaml "char")
-  (Haskell "Prelude.Char")
-  (Scala "Char")
+code_printing
+  type_constructor char \<rightharpoonup>
+    (SML) "char"
+    and (OCaml) "char"
+    and (Haskell) "Prelude.Char"
+    and (Scala) "Char"
 
 setup {*
   fold String_Code.add_literal_char ["SML", "OCaml", "Haskell", "Scala"] 
   #> String_Code.add_literal_list_string "Haskell"
 *}
 
-code_instance char :: equal
-  (Haskell -)
+code_printing
+  class_instance char :: equal \<rightharpoonup>
+    (Haskell) -
+| constant "HOL.equal :: char \<Rightarrow> char \<Rightarrow> bool" \<rightharpoonup>
+    (SML) "!((_ : char) = _)"
+    and (OCaml) "!((_ : char) = _)"
+    and (Haskell) infix 4 "=="
+    and (Scala) infixl 5 "=="
+| constant "Code_Evaluation.term_of \<Colon> char \<Rightarrow> term" \<rightharpoonup>
+    (Eval) "HOLogic.mk'_char/ (IntInf.fromInt/ (Char.ord/ _))"
 
 code_reserved SML
   char
@@ -31,32 +40,22 @@
 code_reserved Scala
   char
 
-code_const "HOL.equal \<Colon> char \<Rightarrow> char \<Rightarrow> bool"
-  (SML "!((_ : char) = _)")
-  (OCaml "!((_ : char) = _)")
-  (Haskell infix 4 "==")
-  (Scala infixl 5 "==")
-
-code_const "Code_Evaluation.term_of \<Colon> char \<Rightarrow> term"
-  (Eval "HOLogic.mk'_char/ (IntInf.fromInt/ (Char.ord/ _))")
-
-
 definition implode :: "string \<Rightarrow> String.literal" where
   "implode = STR"
 
 code_reserved SML String
 
-code_const implode
-  (SML "String.implode")
-  (OCaml "!(let l = _ in let res = String.create (List.length l) in let rec imp i = function | [] -> res | c :: l -> String.set res i c; imp (i + 1) l in imp 0 l)")
-  (Haskell "_")
-  (Scala "!(\"\" ++/ _)")
-
-code_const explode
-  (SML "String.explode")
-  (OCaml "!(let s = _ in let rec exp i l = if i < 0 then l else exp (i - 1) (String.get s i :: l) in exp (String.length s - 1) [])")
-  (Haskell "_")
-  (Scala "!(_.toList)")
+code_printing
+  constant implode \<rightharpoonup>
+    (SML) "String.implode"
+    and (OCaml) "!(let l = _ in let res = String.create (List.length l) in let rec imp i = function | [] -> res | c :: l -> String.set res i c; imp (i + 1) l in imp 0 l)"
+    and (Haskell) "_"
+    and (Scala) "!(\"\" ++/ _)"
+| constant explode \<rightharpoonup>
+    (SML) "String.explode"
+    and (OCaml) "!(let s = _ in let rec exp i l = if i < 0 then l else exp (i - 1) (String.get s i :: l) in exp (String.length s - 1) [])"
+    and (Haskell) "_"
+    and (Scala) "!(_.toList)"
 
 
 definition integer_of_char :: "char \<Rightarrow> integer"
@@ -75,30 +74,29 @@
   "char_of_nat = char_of_integer o integer_of_nat"
   by (simp add: char_of_integer_def fun_eq_iff)
 
-code_const integer_of_char and char_of_integer
-  (SML "!(IntInf.fromInt o Char.ord)"
-    and "!(Char.chr o IntInf.toInt)")
-  (OCaml "Big'_int.big'_int'_of'_int (Char.code _)"
-    and "Char.chr (Big'_int.int'_of'_big'_int _)")
-  (Haskell "Prelude.toInteger (Prelude.fromEnum (_ :: Prelude.Char))"
-    and "!(let chr k | (0 <= k && k < 256) = Prelude.toEnum k :: Prelude.Char in chr . Prelude.fromInteger)")
-  (Scala "BigInt(_.toInt)"
-    and "!((k: BigInt) => if (BigInt(0) <= k && k < BigInt(256)) k.charValue else error(\"character value out of range\"))")
-
-
-code_const "Orderings.less_eq \<Colon> char \<Rightarrow> char \<Rightarrow> bool"
-  (SML "!((_ : char) <= _)")
-  (OCaml "!((_ : char) <= _)")
-  (Haskell infix 4 "<=")
-  (Scala infixl 4 "<=")
-  (Eval infixl 6 "<=")
-
-code_const "Orderings.less \<Colon> char \<Rightarrow> char \<Rightarrow> bool"
-  (SML "!((_ : char) < _)")
-  (OCaml "!((_ : char) < _)")
-  (Haskell infix 4 "<")
-  (Scala infixl 4 "<")
-  (Eval infixl 6 "<")
+code_printing
+  constant integer_of_char \<rightharpoonup>
+    (SML) "!(IntInf.fromInt o Char.ord)"
+    and (OCaml) "Big'_int.big'_int'_of'_int (Char.code _)"
+    and (Haskell) "Prelude.toInteger (Prelude.fromEnum (_ :: Prelude.Char))"
+    and (Scala) "BigInt(_.toInt)"
+| constant char_of_integer \<rightharpoonup>
+    (SML) "!(Char.chr o IntInf.toInt)"
+    and (OCaml) "Char.chr (Big'_int.int'_of'_big'_int _)"
+    and (Haskell) "!(let chr k | (0 <= k && k < 256) = Prelude.toEnum k :: Prelude.Char in chr . Prelude.fromInteger)"
+    and (Scala) "!((k: BigInt) => if (BigInt(0) <= k && k < BigInt(256)) k.charValue else error(\"character value out of range\"))"
+| constant "Orderings.less_eq :: char \<Rightarrow> char \<Rightarrow> bool" \<rightharpoonup>
+    (SML) "!((_ : char) <= _)"
+    and (OCaml) "!((_ : char) <= _)"
+    and (Haskell) infix 4 "<="
+    and (Scala) infixl 4 "<="
+    and (Eval) infixl 6 "<="
+| constant "Orderings.less :: char \<Rightarrow> char \<Rightarrow> bool" \<rightharpoonup>
+    (SML) "!((_ : char) < _)"
+    and (OCaml) "!((_ : char) < _)"
+    and (Haskell) infix 4 "<"
+    and (Scala) infixl 4 "<"
+    and (Eval) infixl 6 "<"
 
 end