src/HOL/Imperative_HOL/Array.thy
author haftmann
Tue, 19 May 2009 13:57:32 +0200
changeset 31203 5c8fb4fd67e0
parent 29822 c45845743f04
child 31205 98370b26c2ce
permissions -rw-r--r--
moved Code_Index, Random and Quickcheck before Main
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     1
(*  Title:      HOL/Library/Array.thy
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     2
    ID:         $Id$
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     3
    Author:     John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     4
*)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     5
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     6
header {* Monadic arrays *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     7
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
     8
theory Array
31203
5c8fb4fd67e0 moved Code_Index, Random and Quickcheck before Main
haftmann
parents: 29822
diff changeset
     9
imports Heap_Monad
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    10
begin
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    11
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    12
subsection {* Primitives *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    13
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    14
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    15
  new :: "nat \<Rightarrow> 'a\<Colon>heap \<Rightarrow> 'a array Heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    16
  [code del]: "new n x = Heap_Monad.heap (Heap.array n x)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    17
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    18
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    19
  of_list :: "'a\<Colon>heap list \<Rightarrow> 'a array Heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    20
  [code del]: "of_list xs = Heap_Monad.heap (Heap.array_of_list xs)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    21
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    22
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    23
  length :: "'a\<Colon>heap array \<Rightarrow> nat Heap" where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    24
  [code del]: "length arr = Heap_Monad.heap (\<lambda>h. (Heap.length arr h, h))"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    25
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    26
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    27
  nth :: "'a\<Colon>heap array \<Rightarrow> nat \<Rightarrow> 'a Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    28
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    29
  [code del]: "nth a i = (do len \<leftarrow> length a;
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    30
                 (if i < len
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    31
                     then Heap_Monad.heap (\<lambda>h. (get_array a h ! i, h))
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    32
                     else raise (''array lookup: index out of range''))
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    33
              done)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    34
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    35
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    36
  upd :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a\<Colon>heap array Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    37
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    38
  [code del]: "upd i x a = (do len \<leftarrow> length a;
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    39
                      (if i < len
26719
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    40
                           then Heap_Monad.heap (\<lambda>h. (a, Heap.upd a i x h))
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    41
                           else raise (''array update: index out of range''))
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    42
                   done)" 
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    43
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    44
lemma upd_return:
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    45
  "upd i x a \<guillemotright> return a = upd i x a"
26719
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    46
proof (rule Heap_eqI)
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    47
  fix h
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    48
  obtain len h' where "Heap_Monad.execute (Array.length a) h = (len, h')"
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    49
    by (cases "Heap_Monad.execute (Array.length a) h")
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    50
  then show "Heap_Monad.execute (upd i x a \<guillemotright> return a) h = Heap_Monad.execute (upd i x a) h"
28145
af3923ed4786 dropped "run" marker in monad syntax
haftmann
parents: 27695
diff changeset
    51
    by (auto simp add: upd_def bindM_def split: sum.split)
26719
a259d259c797 improved definition of upd
haftmann
parents: 26182
diff changeset
    52
qed
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    53
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    54
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    55
subsection {* Derivates *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    56
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    57
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    58
  map_entry :: "nat \<Rightarrow> ('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a array \<Rightarrow> 'a array Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    59
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    60
  "map_entry i f a = (do
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    61
     x \<leftarrow> nth a i;
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    62
     upd i (f x) a
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    63
   done)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    64
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    65
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    66
  swap :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    67
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    68
  "swap i x a = (do
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    69
     y \<leftarrow> nth a i;
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    70
     upd i x a;
27596
bc47d30747e6 dropped map; fixed swap
haftmann
parents: 26752
diff changeset
    71
     return y
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    72
   done)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    73
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    74
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    75
  make :: "nat \<Rightarrow> (nat \<Rightarrow> 'a\<Colon>heap) \<Rightarrow> 'a array Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    76
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    77
  "make n f = of_list (map f [0 ..< n])"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    78
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    79
definition
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    80
  freeze :: "'a\<Colon>heap array \<Rightarrow> 'a list Heap"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    81
where
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    82
  "freeze a = (do
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    83
     n \<leftarrow> length a;
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    84
     mapM (nth a) [0..<n]
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    85
   done)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    86
27656
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    87
definition
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    88
   map :: "('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a array \<Rightarrow> 'a array Heap"
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    89
where
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    90
  "map f a = (do
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    91
     n \<leftarrow> length a;
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    92
     mapM (\<lambda>n. map_entry n f a) [0..<n];
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    93
     return a
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    94
   done)"
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    95
d4f6e64ee7cc added verification framework for the HeapMonad and quicksort as example for this framework
bulwahn
parents: 27596
diff changeset
    96
hide (open) const new map -- {* avoid clashed with some popular names *}
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    97
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    98
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
    99
subsection {* Properties *}
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   100
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   101
lemma array_make [code]:
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   102
  "Array.new n x = make n (\<lambda>_. x)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   103
  by (induct n) (simp_all add: make_def new_def Heap_Monad.heap_def
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   104
    monad_simp array_of_list_replicate [symmetric]
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   105
    map_replicate_trivial replicate_append_same
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   106
    of_list_def)
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   107
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   108
lemma array_of_list_make [code]:
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   109
  "of_list xs = make (List.length xs) (\<lambda>n. xs ! n)"
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   110
  unfolding make_def map_nth ..
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   111
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   112
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   113
subsection {* Code generator setup *}
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   114
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   115
subsubsection {* Logical intermediate layer *}
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   116
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   117
definition new' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   118
  [code del]: "new' = Array.new o Code_Index.nat_of"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   119
hide (open) const new'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   120
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   121
  "Array.new = Array.new' o Code_Index.of_nat"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   122
  by (simp add: new'_def o_def)
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   123
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   124
definition of_list' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   125
  [code del]: "of_list' i xs = Array.of_list (take (Code_Index.nat_of i) xs)"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   126
hide (open) const of_list'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   127
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   128
  "Array.of_list xs = Array.of_list' (Code_Index.of_nat (List.length xs)) xs"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   129
  by (simp add: of_list'_def)
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   130
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   131
definition make' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   132
  [code del]: "make' i f = Array.make (Code_Index.nat_of i) (f o Code_Index.of_nat)"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   133
hide (open) const make'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   134
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   135
  "Array.make n f = Array.make' (Code_Index.of_nat n) (f o Code_Index.nat_of)"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   136
  by (simp add: make'_def o_def)
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   137
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   138
definition length' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   139
  [code del]: "length' = Array.length \<guillemotright>== liftM Code_Index.of_nat"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   140
hide (open) const length'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   141
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   142
  "Array.length = Array.length' \<guillemotright>== liftM Code_Index.nat_of"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   143
  by (simp add: length'_def monad_simp',
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   144
    simp add: liftM_def comp_def monad_simp,
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   145
    simp add: monad_simp')
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   146
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   147
definition nth' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   148
  [code del]: "nth' a = Array.nth a o Code_Index.nat_of"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   149
hide (open) const nth'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   150
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   151
  "Array.nth a n = Array.nth' a (Code_Index.of_nat n)"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   152
  by (simp add: nth'_def)
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   153
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   154
definition upd' where
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   155
  [code del]: "upd' a i x = Array.upd (Code_Index.nat_of i) x a \<guillemotright> return ()"
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   156
hide (open) const upd'
28562
4e74209f113e `code func` now just `code`
haftmann
parents: 28145
diff changeset
   157
lemma [code]:
29815
9e94b7078fa5 mandatory prefix for index conversion operations
haftmann
parents: 29793
diff changeset
   158
  "Array.upd i x a = Array.upd' a (Code_Index.of_nat i) x \<guillemotright> return a"
26743
f4cf7d36c63a fixed proof
haftmann
parents: 26719
diff changeset
   159
  by (simp add: upd'_def monad_simp upd_return)
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   160
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   161
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   162
subsubsection {* SML *}
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   163
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   164
code_type array (SML "_/ array")
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   165
code_const Array (SML "raise/ (Fail/ \"bare Array\")")
26752
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   166
code_const Array.new' (SML "(fn/ ()/ =>/ Array.array/ ((_),/ (_)))")
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   167
code_const Array.of_list (SML "(fn/ ()/ =>/ Array.fromList/ _)")
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   168
code_const Array.make' (SML "(fn/ ()/ =>/ Array.tabulate/ ((_),/ (_)))")
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   169
code_const Array.length' (SML "(fn/ ()/ =>/ Array.length/ _)")
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   170
code_const Array.nth' (SML "(fn/ ()/ =>/ Array.sub/ ((_),/ (_)))")
6b276119139b corrected ML semantics
haftmann
parents: 26743
diff changeset
   171
code_const Array.upd' (SML "(fn/ ()/ =>/ Array.update/ ((_),/ (_),/ (_)))")
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   172
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   173
code_reserved SML Array
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   174
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   175
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   176
subsubsection {* OCaml *}
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   177
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   178
code_type array (OCaml "_/ array")
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   179
code_const Array (OCaml "failwith/ \"bare Array\"")
27673
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   180
code_const Array.new' (OCaml "(fun/ ()/ ->/ Array.make/ _/ _)")
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   181
code_const Array.of_list (OCaml "(fun/ ()/ ->/ Array.of'_list/ _)")
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   182
code_const Array.make' (OCaml "(fun/ ()/ ->/ Array.init/ _/ _)")
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   183
code_const Array.length' (OCaml "(fun/ ()/ ->/ Array.length/ _)")
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   184
code_const Array.nth' (OCaml "(fun/ ()/ ->/ Array.get/ _/ _)")
52056ddac194 fixed code generator setup
haftmann
parents: 27656
diff changeset
   185
code_const Array.upd' (OCaml "(fun/ ()/ ->/ Array.set/ _/ _/ _)")
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   186
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   187
code_reserved OCaml Array
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   188
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   189
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   190
subsubsection {* Haskell *}
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   191
29793
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   192
code_type array (Haskell "Heap.STArray/ Heap.RealWorld/ _")
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   193
code_const Array (Haskell "error/ \"bare Array\"")
29793
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   194
code_const Array.new' (Haskell "Heap.newArray/ (0,/ _)")
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   195
code_const Array.of_list' (Haskell "Heap.newListArray/ (0,/ _)")
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   196
code_const Array.length' (Haskell "Heap.lengthArray")
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   197
code_const Array.nth' (Haskell "Heap.readArray")
86cac1fab613 changed name space policy for Haskell includes
haftmann
parents: 29399
diff changeset
   198
code_const Array.upd' (Haskell "Heap.writeArray")
26182
8262ec0e8782 added code generator setup
haftmann
parents: 26170
diff changeset
   199
26170
66e6b967ccf1 added theories for imperative HOL
haftmann
parents:
diff changeset
   200
end