src/HOL/Library/Code_Char.thy
author haftmann
Fri, 18 Apr 2008 09:44:16 +0200
changeset 26719 a259d259c797
parent 25965 05df64f786a4
child 27368 9f90ac19e32b
permissions -rw-r--r--
improved definition of upd
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
24999
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Code_Char.thy
haftmann
parents:
diff changeset
     2
    ID:         $Id$
haftmann
parents:
diff changeset
     3
    Author:     Florian Haftmann
haftmann
parents:
diff changeset
     4
*)
haftmann
parents:
diff changeset
     5
haftmann
parents:
diff changeset
     6
header {* Code generation of pretty characters (and strings) *}
haftmann
parents:
diff changeset
     7
haftmann
parents:
diff changeset
     8
theory Code_Char
haftmann
parents:
diff changeset
     9
imports List
haftmann
parents:
diff changeset
    10
begin
haftmann
parents:
diff changeset
    11
25965
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    12
declare char.recs [code func del] char.cases [code func del]
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    13
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    14
lemma [code func]:
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    15
  "size (c\<Colon>char) = 0"
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    16
  by (cases c) simp
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    17
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    18
lemma [code func]:
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    19
  "char_size (c\<Colon>char) = 0"
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    20
  by (cases c) simp
05df64f786a4 improved code theorem setup
haftmann
parents: 24999
diff changeset
    21
24999
haftmann
parents:
diff changeset
    22
code_type char
haftmann
parents:
diff changeset
    23
  (SML "char")
haftmann
parents:
diff changeset
    24
  (OCaml "char")
haftmann
parents:
diff changeset
    25
  (Haskell "Char")
haftmann
parents:
diff changeset
    26
haftmann
parents:
diff changeset
    27
setup {*
haftmann
parents:
diff changeset
    28
let
haftmann
parents:
diff changeset
    29
  val charr = @{const_name Char}
haftmann
parents:
diff changeset
    30
  val nibbles = [@{const_name Nibble0}, @{const_name Nibble1},
haftmann
parents:
diff changeset
    31
    @{const_name Nibble2}, @{const_name Nibble3},
haftmann
parents:
diff changeset
    32
    @{const_name Nibble4}, @{const_name Nibble5},
haftmann
parents:
diff changeset
    33
    @{const_name Nibble6}, @{const_name Nibble7},
haftmann
parents:
diff changeset
    34
    @{const_name Nibble8}, @{const_name Nibble9},
haftmann
parents:
diff changeset
    35
    @{const_name NibbleA}, @{const_name NibbleB},
haftmann
parents:
diff changeset
    36
    @{const_name NibbleC}, @{const_name NibbleD},
haftmann
parents:
diff changeset
    37
    @{const_name NibbleE}, @{const_name NibbleF}];
haftmann
parents:
diff changeset
    38
in
haftmann
parents:
diff changeset
    39
  fold (fn target => CodeTarget.add_pretty_char target charr nibbles)
haftmann
parents:
diff changeset
    40
    ["SML", "OCaml", "Haskell"]
haftmann
parents:
diff changeset
    41
  #> CodeTarget.add_pretty_list_string "Haskell"
haftmann
parents:
diff changeset
    42
    @{const_name Nil} @{const_name Cons} charr nibbles
haftmann
parents:
diff changeset
    43
end
haftmann
parents:
diff changeset
    44
*}
haftmann
parents:
diff changeset
    45
haftmann
parents:
diff changeset
    46
code_instance char :: eq
haftmann
parents:
diff changeset
    47
  (Haskell -)
haftmann
parents:
diff changeset
    48
haftmann
parents:
diff changeset
    49
code_reserved SML
haftmann
parents:
diff changeset
    50
  char
haftmann
parents:
diff changeset
    51
haftmann
parents:
diff changeset
    52
code_reserved OCaml
haftmann
parents:
diff changeset
    53
  char
haftmann
parents:
diff changeset
    54
haftmann
parents:
diff changeset
    55
code_const "op = \<Colon> char \<Rightarrow> char \<Rightarrow> bool"
haftmann
parents:
diff changeset
    56
  (SML "!((_ : char) = _)")
haftmann
parents:
diff changeset
    57
  (OCaml "!((_ : char) = _)")
haftmann
parents:
diff changeset
    58
  (Haskell infixl 4 "==")
haftmann
parents:
diff changeset
    59
haftmann
parents:
diff changeset
    60
end