src/HOL/Imperative_HOL/Array.thy
author haftmann
Fri Jul 09 16:58:44 2010 +0200 (2010-07-09 ago)
changeset 37758 bf86a65403a8
parent 37756 59caa6180fff
child 37771 1bec64044b5e
permissions -rw-r--r--
pervasive success combinator
haftmann@31870
     1
(*  Title:      HOL/Imperative_HOL/Array.thy
haftmann@26170
     2
    Author:     John Matthews, Galois Connections; Alexander Krauss, Lukas Bulwahn & Florian Haftmann, TU Muenchen
haftmann@26170
     3
*)
haftmann@26170
     4
haftmann@26170
     5
header {* Monadic arrays *}
haftmann@26170
     6
haftmann@26170
     7
theory Array
haftmann@31203
     8
imports Heap_Monad
haftmann@26170
     9
begin
haftmann@26170
    10
haftmann@37752
    11
subsection {* Primitives *}
haftmann@37719
    12
haftmann@37752
    13
definition (*FIXME present :: "heap \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> bool" where*)
haftmann@37719
    14
  array_present :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> bool" where
haftmann@37719
    15
  "array_present a h \<longleftrightarrow> addr_of_array a < lim h"
haftmann@37719
    16
haftmann@37752
    17
definition (*FIXME get :: "heap \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a list" where*)
haftmann@37719
    18
  get_array :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> 'a list" where
haftmann@37719
    19
  "get_array a h = map from_nat (arrays h (TYPEREP('a)) (addr_of_array a))"
haftmann@37719
    20
haftmann@37752
    21
definition (*FIXME set*)
haftmann@37719
    22
  set_array :: "'a\<Colon>heap array \<Rightarrow> 'a list \<Rightarrow> heap \<Rightarrow> heap" where
haftmann@37719
    23
  "set_array a x = 
haftmann@37719
    24
  arrays_update (\<lambda>h. h(TYPEREP('a) := ((h(TYPEREP('a))) (addr_of_array a:=map to_nat x))))"
haftmann@37719
    25
haftmann@37752
    26
definition (*FIXME alloc*)
haftmann@37752
    27
  array :: "'a list \<Rightarrow> heap \<Rightarrow> 'a\<Colon>heap array \<times> heap" where
haftmann@37719
    28
  "array xs h = (let
haftmann@37719
    29
     l = lim h;
haftmann@37719
    30
     r = Array l;
haftmann@37719
    31
     h'' = set_array r xs (h\<lparr>lim := l + 1\<rparr>)
haftmann@37719
    32
   in (r, h''))"
haftmann@37719
    33
haftmann@37752
    34
definition (*FIXME length :: "heap \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> nat" where*)
haftmann@37752
    35
  length :: "'a\<Colon>heap array \<Rightarrow> heap \<Rightarrow> nat" where
haftmann@37719
    36
  "length a h = List.length (get_array a h)"
haftmann@37719
    37
  
haftmann@37752
    38
definition (*FIXME update*)
haftmann@37752
    39
  change :: "'a\<Colon>heap array \<Rightarrow> nat \<Rightarrow> 'a \<Rightarrow> heap \<Rightarrow> heap" where
haftmann@37719
    40
  "change a i x h = set_array a ((get_array a h)[i:=x]) h"
haftmann@37719
    41
haftmann@37752
    42
definition (*FIXME noteq*)
haftmann@37752
    43
  noteq_arrs :: "'a\<Colon>heap array \<Rightarrow> 'b\<Colon>heap array \<Rightarrow> bool" (infix "=!!=" 70) where
haftmann@37752
    44
  "r =!!= s \<longleftrightarrow> TYPEREP('a) \<noteq> TYPEREP('b) \<or> addr_of_array r \<noteq> addr_of_array s"
haftmann@37752
    45
haftmann@37752
    46
haftmann@37752
    47
subsection {* Monad operations *}
haftmann@37752
    48
haftmann@37752
    49
definition new :: "nat \<Rightarrow> 'a\<Colon>heap \<Rightarrow> 'a array Heap" where
haftmann@37752
    50
  [code del]: "new n x = Heap_Monad.heap (array (replicate n x))"
haftmann@37752
    51
haftmann@37752
    52
definition of_list :: "'a\<Colon>heap list \<Rightarrow> 'a array Heap" where
haftmann@37752
    53
  [code del]: "of_list xs = Heap_Monad.heap (array xs)"
haftmann@37752
    54
haftmann@37752
    55
definition make :: "nat \<Rightarrow> (nat \<Rightarrow> 'a\<Colon>heap) \<Rightarrow> 'a array Heap" where
haftmann@37752
    56
  [code del]: "make n f = Heap_Monad.heap (array (map f [0 ..< n]))"
haftmann@37752
    57
haftmann@37752
    58
definition len :: "'a\<Colon>heap array \<Rightarrow> nat Heap" where
haftmann@37758
    59
  [code del]: "len a = Heap_Monad.tap (\<lambda>h. length a h)"
haftmann@37752
    60
haftmann@37752
    61
definition nth :: "'a\<Colon>heap array \<Rightarrow> nat \<Rightarrow> 'a Heap" where
haftmann@37752
    62
  [code del]: "nth a i = Heap_Monad.guard (\<lambda>h. i < length a h)
haftmann@37752
    63
    (\<lambda>h. (get_array a h ! i, h))"
haftmann@37752
    64
haftmann@37752
    65
definition upd :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a\<Colon>heap array Heap" where
haftmann@37752
    66
  [code del]: "upd i x a = Heap_Monad.guard (\<lambda>h. i < length a h)
haftmann@37752
    67
    (\<lambda>h. (a, change a i x h))"
haftmann@37752
    68
haftmann@37752
    69
definition map_entry :: "nat \<Rightarrow> ('a\<Colon>heap \<Rightarrow> 'a) \<Rightarrow> 'a array \<Rightarrow> 'a array Heap" where
haftmann@37752
    70
  [code del]: "map_entry i f a = Heap_Monad.guard (\<lambda>h. i < length a h)
haftmann@37752
    71
    (\<lambda>h. (a, change a i (f (get_array a h ! i)) h))"
haftmann@37752
    72
haftmann@37752
    73
definition swap :: "nat \<Rightarrow> 'a \<Rightarrow> 'a\<Colon>heap array \<Rightarrow> 'a Heap" where
haftmann@37752
    74
  [code del]: "swap i x a = Heap_Monad.guard (\<lambda>h. i < length a h)
haftmann@37752
    75
    (\<lambda>h. (get_array a h ! i, change a i x h))"
haftmann@37752
    76
haftmann@37752
    77
definition freeze :: "'a\<Colon>heap array \<Rightarrow> 'a list Heap" where
haftmann@37758
    78
  [code del]: "freeze a = Heap_Monad.tap (\<lambda>h. get_array a h)"
haftmann@37752
    79
haftmann@37752
    80
haftmann@37752
    81
subsection {* Properties *}
haftmann@37719
    82
haftmann@37719
    83
text {* FIXME: Does there exist a "canonical" array axiomatisation in
haftmann@37719
    84
the literature?  *}
haftmann@37719
    85
haftmann@37758
    86
text {* Primitives *}
haftmann@37758
    87
haftmann@37719
    88
lemma noteq_arrs_sym: "a =!!= b \<Longrightarrow> b =!!= a"
haftmann@37719
    89
  and unequal_arrs [simp]: "a \<noteq> a' \<longleftrightarrow> a =!!= a'"
haftmann@37719
    90
  unfolding noteq_arrs_def by auto
haftmann@37719
    91
haftmann@37719
    92
lemma noteq_arrs_irrefl: "r =!!= r \<Longrightarrow> False"
haftmann@37719
    93
  unfolding noteq_arrs_def by auto
haftmann@37719
    94
haftmann@37719
    95
lemma present_new_arr: "array_present a h \<Longrightarrow> a =!!= fst (array xs h)"
haftmann@37719
    96
  by (simp add: array_present_def noteq_arrs_def array_def Let_def)
haftmann@37719
    97
haftmann@37719
    98
lemma array_get_set_eq [simp]: "get_array r (set_array r x h) = x"
haftmann@37719
    99
  by (simp add: get_array_def set_array_def o_def)
haftmann@37719
   100
haftmann@37719
   101
lemma array_get_set_neq [simp]: "r =!!= s \<Longrightarrow> get_array r (set_array s x h) = get_array r h"
haftmann@37719
   102
  by (simp add: noteq_arrs_def get_array_def set_array_def)
haftmann@37719
   103
haftmann@37719
   104
lemma set_array_same [simp]:
haftmann@37719
   105
  "set_array r x (set_array r y h) = set_array r x h"
haftmann@37719
   106
  by (simp add: set_array_def)
haftmann@37719
   107
haftmann@37719
   108
lemma array_set_set_swap:
haftmann@37719
   109
  "r =!!= r' \<Longrightarrow> set_array r x (set_array r' x' h) = set_array r' x' (set_array r x h)"
haftmann@37719
   110
  by (simp add: Let_def expand_fun_eq noteq_arrs_def set_array_def)
haftmann@37719
   111
haftmann@37719
   112
lemma get_array_change_eq [simp]:
haftmann@37719
   113
  "get_array a (change a i v h) = (get_array a h) [i := v]"
haftmann@37719
   114
  by (simp add: change_def)
haftmann@37719
   115
haftmann@37719
   116
lemma nth_change_array_neq_array [simp]:
haftmann@37719
   117
  "a =!!= b \<Longrightarrow> get_array a (change b j v h) ! i = get_array a h ! i"
haftmann@37719
   118
  by (simp add: change_def noteq_arrs_def)
haftmann@37719
   119
haftmann@37719
   120
lemma get_arry_array_change_elem_neqIndex [simp]:
haftmann@37719
   121
  "i \<noteq> j \<Longrightarrow> get_array a (change a j v h) ! i = get_array a h ! i"
haftmann@37719
   122
  by simp
haftmann@37719
   123
haftmann@37719
   124
lemma length_change [simp]: 
haftmann@37719
   125
  "length a (change b i v h) = length a h"
haftmann@37719
   126
  by (simp add: change_def length_def set_array_def get_array_def)
haftmann@37719
   127
haftmann@37719
   128
lemma change_swap_neqArray:
haftmann@37719
   129
  "a =!!= a' \<Longrightarrow> 
haftmann@37719
   130
  change a i v (change a' i' v' h) 
haftmann@37719
   131
  = change a' i' v' (change a i v h)"
haftmann@37719
   132
apply (unfold change_def)
haftmann@37719
   133
apply simp
haftmann@37719
   134
apply (subst array_set_set_swap, assumption)
haftmann@37719
   135
apply (subst array_get_set_neq)
haftmann@37719
   136
apply (erule noteq_arrs_sym)
haftmann@37719
   137
apply (simp)
haftmann@37719
   138
done
haftmann@37719
   139
haftmann@37719
   140
lemma change_swap_neqIndex:
haftmann@37719
   141
  "\<lbrakk> i \<noteq> i' \<rbrakk> \<Longrightarrow> change a i v (change a i' v' h) = change a i' v' (change a i v h)"
haftmann@37719
   142
  by (auto simp add: change_def array_set_set_swap list_update_swap)
haftmann@37719
   143
haftmann@37719
   144
lemma get_array_init_array_list:
haftmann@37719
   145
  "get_array (fst (array ls h)) (snd (array ls' h)) = ls'"
haftmann@37719
   146
  by (simp add: Let_def split_def array_def)
haftmann@37719
   147
haftmann@37719
   148
lemma set_array:
haftmann@37719
   149
  "set_array (fst (array ls h))
haftmann@37719
   150
     new_ls (snd (array ls h))
haftmann@37719
   151
       = snd (array new_ls h)"
haftmann@37719
   152
  by (simp add: Let_def split_def array_def)
haftmann@37719
   153
haftmann@37719
   154
lemma array_present_change [simp]: 
haftmann@37719
   155
  "array_present a (change b i v h) = array_present a h"
haftmann@37719
   156
  by (simp add: change_def array_present_def set_array_def get_array_def)
haftmann@37719
   157
haftmann@37758
   158
haftmann@37758
   159
text {* Monad operations *}
haftmann@37758
   160
haftmann@37758
   161
lemma execute_new [simp, execute_simps]:
haftmann@37758
   162
  "execute (new n x) h = Some (array (replicate n x) h)"
haftmann@37758
   163
  by (simp add: new_def)
haftmann@37758
   164
haftmann@37758
   165
lemma success_newI [iff, success_intros]:
haftmann@37758
   166
  "success (new n x) h"
haftmann@37752
   167
  by (simp add: new_def)
haftmann@26170
   168
haftmann@37758
   169
lemma execute_of_list [simp, execute_simps]:
haftmann@37758
   170
  "execute (of_list xs) h = Some (array xs h)"
haftmann@37758
   171
  by (simp add: of_list_def)
haftmann@37758
   172
haftmann@37758
   173
lemma success_of_listI [iff, success_intros]:
haftmann@37758
   174
  "success (of_list xs) h"
haftmann@37752
   175
  by (simp add: of_list_def)
haftmann@26170
   176
haftmann@37758
   177
lemma execute_make [simp, execute_simps]:
haftmann@37758
   178
  "execute (make n f) h = Some (array (map f [0 ..< n]) h)"
haftmann@37752
   179
  by (simp add: make_def)
haftmann@26170
   180
haftmann@37758
   181
lemma success_makeI [iff, success_intros]:
haftmann@37758
   182
  "success (make n f) h"
haftmann@37758
   183
  by (simp add: make_def)
haftmann@37758
   184
haftmann@37758
   185
lemma execute_len [simp, execute_simps]:
haftmann@37758
   186
  "execute (len a) h = Some (length a h, h)"
haftmann@37758
   187
  by (simp add: len_def)
haftmann@37758
   188
haftmann@37758
   189
lemma success_lenI [iff, success_intros]:
haftmann@37758
   190
  "success (len a) h"
haftmann@37752
   191
  by (simp add: len_def)
haftmann@37752
   192
haftmann@37758
   193
lemma execute_nth [execute_simps]:
haftmann@37752
   194
  "i < length a h \<Longrightarrow>
haftmann@37758
   195
    execute (nth a i) h = Some (get_array a h ! i, h)"
haftmann@37758
   196
  "i \<ge> length a h \<Longrightarrow> execute (nth a i) h = None"
haftmann@37758
   197
  by (simp_all add: nth_def execute_simps)
haftmann@37758
   198
haftmann@37758
   199
lemma success_nthI [success_intros]:
haftmann@37758
   200
  "i < length a h \<Longrightarrow> success (nth a i) h"
haftmann@37758
   201
  by (auto intro: success_intros simp add: nth_def)
haftmann@26170
   202
haftmann@37758
   203
lemma execute_upd [execute_simps]:
haftmann@37752
   204
  "i < length a h \<Longrightarrow>
haftmann@37758
   205
    execute (upd i x a) h = Some (a, change a i x h)"
haftmann@37758
   206
  "i \<ge> length a h \<Longrightarrow> execute (nth a i) h = None"
haftmann@37758
   207
  by (simp_all add: upd_def execute_simps)
haftmann@26170
   208
haftmann@37758
   209
lemma success_updI [success_intros]:
haftmann@37758
   210
  "i < length a h \<Longrightarrow> success (upd i x a) h"
haftmann@37758
   211
  by (auto intro: success_intros simp add: upd_def)
haftmann@37758
   212
haftmann@37758
   213
lemma execute_map_entry [execute_simps]:
haftmann@37752
   214
  "i < length a h \<Longrightarrow>
haftmann@37758
   215
   execute (map_entry i f a) h =
haftmann@37752
   216
      Some (a, change a i (f (get_array a h ! i)) h)"
haftmann@37758
   217
  "i \<ge> length a h \<Longrightarrow> execute (nth a i) h = None"
haftmann@37758
   218
  by (simp_all add: map_entry_def execute_simps)
haftmann@37752
   219
haftmann@37758
   220
lemma success_map_entryI [success_intros]:
haftmann@37758
   221
  "i < length a h \<Longrightarrow> success (map_entry i f a) h"
haftmann@37758
   222
  by (auto intro: success_intros simp add: map_entry_def)
haftmann@37758
   223
haftmann@37758
   224
lemma execute_swap [execute_simps]:
haftmann@37752
   225
  "i < length a h \<Longrightarrow>
haftmann@37758
   226
   execute (swap i x a) h =
haftmann@37752
   227
      Some (get_array a h ! i, change a i x h)"
haftmann@37758
   228
  "i \<ge> length a h \<Longrightarrow> execute (nth a i) h = None"
haftmann@37758
   229
  by (simp_all add: swap_def execute_simps)
haftmann@37758
   230
haftmann@37758
   231
lemma success_swapI [success_intros]:
haftmann@37758
   232
  "i < length a h \<Longrightarrow> success (swap i x a) h"
haftmann@37758
   233
  by (auto intro: success_intros simp add: swap_def)
haftmann@37752
   234
haftmann@37758
   235
lemma execute_freeze [simp, execute_simps]:
haftmann@37758
   236
  "execute (freeze a) h = Some (get_array a h, h)"
haftmann@37758
   237
  by (simp add: freeze_def)
haftmann@37758
   238
haftmann@37758
   239
lemma success_freezeI [iff, success_intros]:
haftmann@37758
   240
  "success (freeze a) h"
haftmann@37752
   241
  by (simp add: freeze_def)
haftmann@26170
   242
haftmann@26170
   243
lemma upd_return:
haftmann@26170
   244
  "upd i x a \<guillemotright> return a = upd i x a"
haftmann@37756
   245
  by (rule Heap_eqI) (simp add: bind_def guard_def upd_def)
haftmann@26170
   246
haftmann@37752
   247
lemma array_make:
haftmann@37752
   248
  "new n x = make n (\<lambda>_. x)"
haftmann@37752
   249
  by (rule Heap_eqI) (simp add: map_replicate_trivial)
haftmann@26170
   250
haftmann@37752
   251
lemma array_of_list_make:
haftmann@37752
   252
  "of_list xs = make (List.length xs) (\<lambda>n. xs ! n)"
haftmann@37752
   253
  by (rule Heap_eqI) (simp add: map_nth)
haftmann@26170
   254
haftmann@37752
   255
hide_const (open) new map
haftmann@26170
   256
haftmann@26182
   257
haftmann@26182
   258
subsection {* Code generator setup *}
haftmann@26182
   259
haftmann@26182
   260
subsubsection {* Logical intermediate layer *}
haftmann@26182
   261
haftmann@26182
   262
definition new' where
haftmann@31205
   263
  [code del]: "new' = Array.new o Code_Numeral.nat_of"
haftmann@37752
   264
haftmann@28562
   265
lemma [code]:
haftmann@37752
   266
  "Array.new = new' o Code_Numeral.of_nat"
haftmann@26182
   267
  by (simp add: new'_def o_def)
haftmann@26182
   268
haftmann@26182
   269
definition of_list' where
haftmann@31205
   270
  [code del]: "of_list' i xs = Array.of_list (take (Code_Numeral.nat_of i) xs)"
haftmann@37752
   271
haftmann@28562
   272
lemma [code]:
haftmann@37752
   273
  "Array.of_list xs = of_list' (Code_Numeral.of_nat (List.length xs)) xs"
haftmann@26182
   274
  by (simp add: of_list'_def)
haftmann@26182
   275
haftmann@26182
   276
definition make' where
haftmann@31205
   277
  [code del]: "make' i f = Array.make (Code_Numeral.nat_of i) (f o Code_Numeral.of_nat)"
haftmann@37752
   278
haftmann@28562
   279
lemma [code]:
haftmann@37752
   280
  "Array.make n f = make' (Code_Numeral.of_nat n) (f o Code_Numeral.nat_of)"
haftmann@26182
   281
  by (simp add: make'_def o_def)
haftmann@26182
   282
haftmann@37719
   283
definition len' where
haftmann@37719
   284
  [code del]: "len' a = Array.len a \<guillemotright>= (\<lambda>n. return (Code_Numeral.of_nat n))"
haftmann@37752
   285
haftmann@28562
   286
lemma [code]:
haftmann@37752
   287
  "Array.len a = len' a \<guillemotright>= (\<lambda>i. return (Code_Numeral.nat_of i))"
haftmann@37719
   288
  by (simp add: len'_def)
haftmann@26182
   289
haftmann@26182
   290
definition nth' where
haftmann@31205
   291
  [code del]: "nth' a = Array.nth a o Code_Numeral.nat_of"
haftmann@37752
   292
haftmann@28562
   293
lemma [code]:
haftmann@37752
   294
  "Array.nth a n = nth' a (Code_Numeral.of_nat n)"
haftmann@26182
   295
  by (simp add: nth'_def)
haftmann@26182
   296
haftmann@26182
   297
definition upd' where
haftmann@31205
   298
  [code del]: "upd' a i x = Array.upd (Code_Numeral.nat_of i) x a \<guillemotright> return ()"
haftmann@37752
   299
haftmann@28562
   300
lemma [code]:
haftmann@37752
   301
  "Array.upd i x a = upd' a (Code_Numeral.of_nat i) x \<guillemotright> return a"
haftmann@37709
   302
  by (simp add: upd'_def upd_return)
haftmann@26182
   303
haftmann@37752
   304
lemma [code]:
haftmann@37752
   305
  "map_entry i f a = (do
haftmann@37752
   306
     x \<leftarrow> nth a i;
haftmann@37752
   307
     upd i (f x) a
haftmann@37752
   308
   done)"
haftmann@37758
   309
  by (rule Heap_eqI) (simp add: bind_def guard_def map_entry_def execute_simps)
haftmann@26182
   310
haftmann@37752
   311
lemma [code]:
haftmann@37752
   312
  "swap i x a = (do
haftmann@37752
   313
     y \<leftarrow> nth a i;
haftmann@37752
   314
     upd i x a;
haftmann@37752
   315
     return y
haftmann@37752
   316
   done)"
haftmann@37758
   317
  by (rule Heap_eqI) (simp add: bind_def guard_def swap_def execute_simps)
haftmann@37752
   318
haftmann@37752
   319
lemma [code]:
haftmann@37752
   320
  "freeze a = (do
haftmann@37752
   321
     n \<leftarrow> len a;
haftmann@37756
   322
     Heap_Monad.fold_map (\<lambda>i. nth a i) [0..<n]
haftmann@37752
   323
   done)"
haftmann@37752
   324
proof (rule Heap_eqI)
haftmann@37752
   325
  fix h
haftmann@37752
   326
  have *: "List.map
haftmann@37752
   327
     (\<lambda>x. fst (the (if x < length a h
haftmann@37752
   328
                    then Some (get_array a h ! x, h) else None)))
haftmann@37752
   329
     [0..<length a h] =
haftmann@37752
   330
       List.map (List.nth (get_array a h)) [0..<length a h]"
haftmann@37752
   331
    by simp
haftmann@37758
   332
  have "execute (Heap_Monad.fold_map (Array.nth a) [0..<length a h]) h =
haftmann@37752
   333
    Some (get_array a h, h)"
haftmann@37756
   334
    apply (subst execute_fold_map_unchanged_heap)
haftmann@37752
   335
    apply (simp_all add: nth_def guard_def *)
haftmann@37752
   336
    apply (simp add: length_def map_nth)
haftmann@37752
   337
    done
haftmann@37758
   338
  then have "execute (do
haftmann@37752
   339
      n \<leftarrow> len a;
haftmann@37756
   340
      Heap_Monad.fold_map (Array.nth a) [0..<n]
haftmann@37752
   341
    done) h = Some (get_array a h, h)"
haftmann@37752
   342
    by (auto intro: execute_eq_SomeI)
haftmann@37758
   343
  then show "execute (freeze a) h = execute (do
haftmann@37752
   344
      n \<leftarrow> len a;
haftmann@37756
   345
      Heap_Monad.fold_map (Array.nth a) [0..<n]
haftmann@37752
   346
    done) h" by simp
haftmann@37752
   347
qed
haftmann@37752
   348
haftmann@37752
   349
hide_const (open) new' of_list' make' len' nth' upd'
haftmann@37752
   350
haftmann@37752
   351
haftmann@37752
   352
text {* SML *}
haftmann@26182
   353
haftmann@26182
   354
code_type array (SML "_/ array")
haftmann@26182
   355
code_const Array (SML "raise/ (Fail/ \"bare Array\")")
haftmann@26752
   356
code_const Array.new' (SML "(fn/ ()/ =>/ Array.array/ ((_),/ (_)))")
haftmann@35846
   357
code_const Array.of_list' (SML "(fn/ ()/ =>/ Array.fromList/ _)")
haftmann@26752
   358
code_const Array.make' (SML "(fn/ ()/ =>/ Array.tabulate/ ((_),/ (_)))")
haftmann@37719
   359
code_const Array.len' (SML "(fn/ ()/ =>/ Array.length/ _)")
haftmann@26752
   360
code_const Array.nth' (SML "(fn/ ()/ =>/ Array.sub/ ((_),/ (_)))")
haftmann@26752
   361
code_const Array.upd' (SML "(fn/ ()/ =>/ Array.update/ ((_),/ (_),/ (_)))")
haftmann@26182
   362
haftmann@26182
   363
code_reserved SML Array
haftmann@26182
   364
haftmann@26182
   365
haftmann@37752
   366
text {* OCaml *}
haftmann@26182
   367
haftmann@26182
   368
code_type array (OCaml "_/ array")
haftmann@26182
   369
code_const Array (OCaml "failwith/ \"bare Array\"")
haftmann@32580
   370
code_const Array.new' (OCaml "(fun/ ()/ ->/ Array.make/ (Big'_int.int'_of'_big'_int/ _)/ _)")
haftmann@35846
   371
code_const Array.of_list' (OCaml "(fun/ ()/ ->/ Array.of'_list/ _)")
haftmann@37719
   372
code_const Array.len' (OCaml "(fun/ ()/ ->/ Big'_int.big'_int'_of'_int/ (Array.length/ _))")
haftmann@32580
   373
code_const Array.nth' (OCaml "(fun/ ()/ ->/ Array.get/ _/ (Big'_int.int'_of'_big'_int/ _))")
haftmann@32580
   374
code_const Array.upd' (OCaml "(fun/ ()/ ->/ Array.set/ _/ (Big'_int.int'_of'_big'_int/ _)/ _)")
haftmann@26182
   375
haftmann@26182
   376
code_reserved OCaml Array
haftmann@26182
   377
haftmann@26182
   378
haftmann@37752
   379
text {* Haskell *}
haftmann@26182
   380
haftmann@29793
   381
code_type array (Haskell "Heap.STArray/ Heap.RealWorld/ _")
haftmann@26182
   382
code_const Array (Haskell "error/ \"bare Array\"")
haftmann@29793
   383
code_const Array.new' (Haskell "Heap.newArray/ (0,/ _)")
haftmann@29793
   384
code_const Array.of_list' (Haskell "Heap.newListArray/ (0,/ _)")
haftmann@37719
   385
code_const Array.len' (Haskell "Heap.lengthArray")
haftmann@29793
   386
code_const Array.nth' (Haskell "Heap.readArray")
haftmann@29793
   387
code_const Array.upd' (Haskell "Heap.writeArray")
haftmann@26182
   388
haftmann@26170
   389
end