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