src/Pure/General/array.ML
author wenzelm
Tue, 26 Mar 2024 21:44:18 +0100
changeset 80018 ac4412562c7b
parent 77896 a9626bcb0c3b
permissions -rw-r--r--
more robust XML body: allow empty text, as well as arbitrary pro-forma markup (e.g. see XML.blob in Isabelle/ML);
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
77887
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     1
(*  Title:      Pure/General/array.ML
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     2
    Author:     Makarius
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     3
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     4
Additional operations for structure Array, following Isabelle/ML conventions.
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     5
*)
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     6
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     7
signature ARRAY =
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     8
sig
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
     9
  include ARRAY
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    10
  val nth: 'a array -> int -> 'a
77896
a9626bcb0c3b tuned signature;
wenzelm
parents: 77887
diff changeset
    11
  val upd: 'a array -> int -> 'a -> unit
77887
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    12
  val forall: ('a -> bool) -> 'a array -> bool
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    13
  val member: ('a * 'a -> bool) -> 'a array -> 'a -> bool
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    14
  val fold: ('a -> 'b -> 'b) -> 'a array -> 'b -> 'b
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    15
  val fold_rev: ('a -> 'b -> 'b) -> 'a array -> 'b -> 'b
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    16
end;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    17
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    18
structure Array: ARRAY =
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    19
struct
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    20
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    21
open Array;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    22
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    23
fun nth arr i = sub (arr, i);
77896
a9626bcb0c3b tuned signature;
wenzelm
parents: 77887
diff changeset
    24
fun upd arr i x = update (arr, i, x);
77887
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    25
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    26
val forall = all;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    27
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    28
fun member eq arr x = exists (fn y => eq (x, y)) arr;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    29
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    30
fun fold f arr x = foldl (fn (a, b) => f a b) x arr;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    31
fun fold_rev f arr x = foldr (fn (a, b) => f a b) x arr;
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    32
dae8b7a9a89a more operations, following Isabelle/ML conventions;
wenzelm
parents:
diff changeset
    33
end;