src/HOL/Library/Pretty_Int.thy
author chaieb
Mon Jun 11 11:06:04 2007 +0200 (2007-06-11)
changeset 23315 df3a7e9ebadb
parent 22949 997cef733bdd
child 23859 fc44fa554ca8
permissions -rw-r--r--
tuned Proof
haftmann@22803
     1
(*  Title:      HOL/Library/Pretty_Int.thy
haftmann@22803
     2
    ID:         $Id$
haftmann@22767
     3
    Author:     Florian Haftmann, TU Muenchen
haftmann@22767
     4
*)
haftmann@22767
     5
haftmann@22767
     6
header {* Pretty integer literals for code generation *}
haftmann@22767
     7
haftmann@22767
     8
theory Pretty_Int
haftmann@22767
     9
imports IntArith
haftmann@22767
    10
begin
haftmann@22767
    11
haftmann@22767
    12
text {*
haftmann@22767
    13
  HOL numeral expressions are mapped to integer literals
haftmann@22767
    14
  in target languages, using predefined target language
haftmann@22767
    15
  operations for abstract integer operations.
haftmann@22767
    16
*}
haftmann@22767
    17
haftmann@22767
    18
code_type int
haftmann@22767
    19
  (SML "IntInf.int")
haftmann@22767
    20
  (OCaml "Big'_int.big'_int")
haftmann@22767
    21
  (Haskell "Integer")
haftmann@22767
    22
haftmann@22949
    23
code_instance int :: eq
haftmann@22949
    24
  (Haskell -)
haftmann@22949
    25
haftmann@22767
    26
setup {*
haftmann@22767
    27
  fold (fn target => CodegenSerializer.add_pretty_numeral target
haftmann@22767
    28
    (@{const_name number_of}, @{typ "int \<Rightarrow> int"})
haftmann@22767
    29
    @{const_name Numeral.B0} @{const_name Numeral.B1}
haftmann@22767
    30
    @{const_name Numeral.Pls} @{const_name Numeral.Min}
haftmann@22767
    31
    @{const_name Numeral.Bit}
haftmann@22767
    32
  ) ["SML", "OCaml", "Haskell"]
haftmann@22767
    33
*}
haftmann@22767
    34
haftmann@22767
    35
code_const "Numeral.Pls" and "Numeral.Min" and "Numeral.Bit"
haftmann@22767
    36
  (SML "raise/ Fail/ \"Pls\""
haftmann@22767
    37
     and "raise/ Fail/ \"Min\""
haftmann@22767
    38
     and "!((_);/ (_);/ raise/ Fail/ \"Bit\")")
haftmann@22767
    39
  (OCaml "failwith/ \"Pls\""
haftmann@22767
    40
     and "failwith/ \"Min\""
haftmann@22767
    41
     and "!((_);/ (_);/ failwith/ \"Bit\")")
haftmann@22767
    42
  (Haskell "error/ \"Pls\""
haftmann@22767
    43
     and "error/ \"Min\""
haftmann@22767
    44
     and "error/ \"Bit\"")
haftmann@22767
    45
haftmann@22767
    46
code_const Numeral.pred
haftmann@22767
    47
  (SML "IntInf.- ((_), 1)")
haftmann@22767
    48
  (OCaml "Big'_int.pred'_big'_int")
haftmann@22767
    49
  (Haskell "!(_/ -/ 1)")
haftmann@22767
    50
haftmann@22767
    51
code_const Numeral.succ
haftmann@22767
    52
  (SML "IntInf.+ ((_), 1)")
haftmann@22767
    53
  (OCaml "Big'_int.succ'_big'_int")
haftmann@22767
    54
  (Haskell "!(_/ +/ 1)")
haftmann@22767
    55
haftmann@22767
    56
code_const "op + \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@22767
    57
  (SML "IntInf.+ ((_), (_))")
haftmann@22767
    58
  (OCaml "Big'_int.add'_big'_int")
haftmann@22767
    59
  (Haskell infixl 6 "+")
haftmann@22767
    60
haftmann@22767
    61
code_const "uminus \<Colon> int \<Rightarrow> int"
haftmann@22767
    62
  (SML "IntInf.~")
haftmann@22767
    63
  (OCaml "Big'_int.minus'_big'_int")
haftmann@22767
    64
  (Haskell "negate")
haftmann@22767
    65
haftmann@22767
    66
code_const "op - \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@22767
    67
  (SML "IntInf.- ((_), (_))")
haftmann@22767
    68
  (OCaml "Big'_int.sub'_big'_int")
haftmann@22767
    69
  (Haskell infixl 6 "-")
haftmann@22767
    70
haftmann@22767
    71
code_const "op * \<Colon> int \<Rightarrow> int \<Rightarrow> int"
haftmann@22767
    72
  (SML "IntInf.* ((_), (_))")
haftmann@22767
    73
  (OCaml "Big'_int.mult'_big'_int")
haftmann@22767
    74
  (Haskell infixl 7 "*")
haftmann@22767
    75
haftmann@22767
    76
code_const "op = \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@22767
    77
  (SML "!((_ : IntInf.int) = _)")
haftmann@22767
    78
  (OCaml "Big'_int.eq'_big'_int")
haftmann@22767
    79
  (Haskell infixl 4 "==")
haftmann@22767
    80
haftmann@22767
    81
code_const "op \<le> \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@22767
    82
  (SML "IntInf.<= ((_), (_))")
haftmann@22767
    83
  (OCaml "Big'_int.le'_big'_int")
haftmann@22767
    84
  (Haskell infix 4 "<=")
haftmann@22767
    85
haftmann@22767
    86
code_const "op < \<Colon> int \<Rightarrow> int \<Rightarrow> bool"
haftmann@22767
    87
  (SML "IntInf.< ((_), (_))")
haftmann@22767
    88
  (OCaml "Big'_int.lt'_big'_int")
haftmann@22767
    89
  (Haskell infix 4 "<")
haftmann@22767
    90
haftmann@22767
    91
code_reserved SML IntInf
haftmann@22767
    92
code_reserved OCaml Big_int
haftmann@22767
    93
haftmann@22767
    94
end