src/Pure/General/vector.ML
author wenzelm
Sun, 27 Oct 2024 11:02:21 +0100
changeset 81266 8300511f4c45
parent 77853 5286dae99de3
permissions -rw-r--r--
clarified signature;

(*  Title:      Pure/General/vector.ML
    Author:     Makarius

Additional operations for structure Vector, following Isabelle/ML conventions.
*)

signature VECTOR =
sig
  include VECTOR
  val nth: 'a vector -> int -> 'a
  val forall: ('a -> bool) -> 'a vector -> bool
  val member: ('a * 'a -> bool) -> 'a vector -> 'a -> bool
  val fold: ('a -> 'b -> 'b) -> 'a vector -> 'b -> 'b
  val fold_rev: ('a -> 'b -> 'b) -> 'a vector -> 'b -> 'b
end;

structure Vector: VECTOR =
struct

open Vector;

fun nth vec i = sub (vec, i);

val forall = all;

fun member eq vec x = exists (fn y => eq (x, y)) vec;

fun fold f vec x = foldl (fn (a, b) => f a b) x vec;
fun fold_rev f vec x = foldr (fn (a, b) => f a b) x vec;

end;