77887
|
1 |
(* Title: Pure/General/array.ML
|
|
2 |
Author: Makarius
|
|
3 |
|
|
4 |
Additional operations for structure Array, following Isabelle/ML conventions.
|
|
5 |
*)
|
|
6 |
|
|
7 |
signature ARRAY =
|
|
8 |
sig
|
|
9 |
include ARRAY
|
|
10 |
val nth: 'a array -> int -> 'a
|
77896
|
11 |
val upd: 'a array -> int -> 'a -> unit
|
77887
|
12 |
val forall: ('a -> bool) -> 'a array -> bool
|
|
13 |
val member: ('a * 'a -> bool) -> 'a array -> 'a -> bool
|
|
14 |
val fold: ('a -> 'b -> 'b) -> 'a array -> 'b -> 'b
|
|
15 |
val fold_rev: ('a -> 'b -> 'b) -> 'a array -> 'b -> 'b
|
|
16 |
end;
|
|
17 |
|
|
18 |
structure Array: ARRAY =
|
|
19 |
struct
|
|
20 |
|
|
21 |
open Array;
|
|
22 |
|
|
23 |
fun nth arr i = sub (arr, i);
|
77896
|
24 |
fun upd arr i x = update (arr, i, x);
|
77887
|
25 |
|
|
26 |
val forall = all;
|
|
27 |
|
|
28 |
fun member eq arr x = exists (fn y => eq (x, y)) arr;
|
|
29 |
|
|
30 |
fun fold f arr x = foldl (fn (a, b) => f a b) x arr;
|
|
31 |
fun fold_rev f arr x = foldr (fn (a, b) => f a b) x arr;
|
|
32 |
|
|
33 |
end;
|