Up

Module Permissioned

The Permissioned module gives the ability to restrict permissions on an array, so you can give a function read-only access to an array, create an immutable array, etc.

Signature

type ('a, -'perms) t

The meaning of the 'perms parameter is as usual (see the Perms module for more details) with the non-obvious difference that you don't need any permissions to extract the length of an array. This was done for simplicity because some information about the length of an array can leak out even if you only have write permissions since you can catch out-of-bounds errors.

val t_of_sexp : (Sexplib.Sexp.t -> 'a) -> (Sexplib.Sexp.t -> 'perms) -> Sexplib.Sexp.t -> ('a, 'perms) t
val sexp_of_t : ('a -> Sexplib.Sexp.t) -> ('perms -> Sexplib.Sexp.t) -> ('a, 'perms) t -> Sexplib.Sexp.t
val compare : ('a -> 'a -> int) -> ('perms -> 'perms -> int) -> ('a, 'perms) t -> ('a, 'perms) t -> int
val bin_t : 'a Bin_prot.Type_class.t -> 'perms Bin_prot.Type_class.t -> ('a, 'perms) t Bin_prot.Type_class.t
val bin_read_t : 'a Bin_prot.Read.reader -> 'perms Bin_prot.Read.reader -> ('a, 'perms) t Bin_prot.Read.reader
val __bin_read_t__ : 'a Bin_prot.Read.reader -> 'perms Bin_prot.Read.reader -> (int -> ('a, 'perms) t) Bin_prot.Read.reader
val bin_size_t : 'a Bin_prot.Size.sizer -> 'perms Bin_prot.Size.sizer -> ('a, 'perms) t Bin_prot.Size.sizer
val bin_write_t : 'a Bin_prot.Write.writer -> 'perms Bin_prot.Write.writer -> ('a, 'perms) t Bin_prot.Write.writer
module Int : sig .. end
module Float : sig .. end
val of_array_id : 'a array -> ('a, [< ]) t

of_array_id and to_array_id return the same underlying array. On the other hand, to_array (inherited from Container.S1_permissions below) makes a copy.

To create a new (possibly immutable) copy of an array a, use copy (of_array_id a). More generally, any function that takes a (possibly mutable) t can be called on an array by calling of_array_id on it first.

There is a conceptual type equality between 'a Array.t and ('a, read_write) Array.Permissioned.t. The reason for not exposing this as an actual type equality is that we also want:

  • The type equality 'a Array.t = 'a array for interoperability with code which does not use Core.
  • The type ('a, 'perms) Array.Permissioned.t to be abstract, so that the permission phantom type will have an effect.

Since we don't control the definition of 'a array, this would require a type ('a, 'perms) Array.Permissioned.t which is abstract, except that ('a, read_write) Array.Permissioned.t is concrete, which is not possible.

val to_array_id : ('a, [> ]) t -> 'a array
val to_sequence_immutable : ('a, [> ]) t -> 'a Core_kernel.Sequence.t

to_sequence_immutable t converts t to a sequence. Unlike to_sequence, to_sequence_immutable does not need to copy t since it is immutable.

include Core_kernel.Container.S1_permissions with type ('a, 'perms) t := ('a, 'perms) t
type ('a, -'permissions) t
val mem : ?equal:('a -> 'a -> bool) -> ('a, [> ]) t -> 'a -> bool

Checks whether the provided element is there, using polymorphic compare if equal is not provided

val length : (_, [> ]) t -> int
val is_empty : (_, [> ]) t -> bool
val iter : ('a, [> ]) t -> f:('a -> unit) -> unit
val fold : ('a, [> ]) t -> init:'accum -> f:('accum -> 'a -> 'accum) -> 'accum

fold t ~init ~f returns f (... f (f (f init e1) e2) e3 ...) en, where e1..en are the elements of t

val exists : ('a, [> ]) t -> f:('a -> bool) -> bool

Returns true if and only if there exists an element for which the provided function evaluates to true. This is a short-circuiting operation.

val for_all : ('a, [> ]) t -> f:('a -> bool) -> bool

Returns true if and only if the provided function evaluates to true for all elements. This is a short-circuiting operation.

val count : ('a, [> ]) t -> f:('a -> bool) -> int

Returns the number of elements for which the provided function evaluates to true.

val sum : (module Commutative_group.S with type t = 'sum) -> ('a, [> ]) t -> f:('a -> 'sum) -> 'sum

Returns the sum of f i for i in the container

val find : ('a, [> ]) t -> f:('a -> bool) -> 'a option

Returns as an option the first element for which f evaluates to true.

val find_map : ('a, [> ]) t -> f:('a -> 'b option) -> 'b option

Returns the first evaluation of f that returns Some, and returns None if there is no such element.

val to_list : ('a, [> ]) t -> 'a list
val to_array : ('a, [> ]) t -> 'a array
val min_elt : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> 'a option

Returns a min (resp max) element from the collection using the provided cmp function. In case of a tie, the first element encountered while traversing the collection is returned. The implementation uses fold so it has the same complexity as fold. Returns None iff the collection is empty.

val max_elt : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> 'a option
include Core_kernel.Blit.S1_permissions with type ('a, 'perms) t := ('a, 'perms) t
type ('a, -'perms) t
val blit : (('a, [> ]) t, ('a, [> ]) t) Blit_intf.blit
val blito : (('a, [> ]) t, ('a, [> ]) t) Blit_intf.blito
val unsafe_blit : (('a, [> ]) t, ('a, [> ]) t) Blit_intf.blit
val sub : (('a, [> ]) t, ('a, [< ]) t) Blit_intf.sub
val subo : (('a, [> ]) t, ('a, [< ]) t) Blit_intf.subo
include Core_kernel.Binary_searchable.S1_permissions with type ('a, 'perms) t := ('a, 'perms) t
type ('a, -'perms) t
val binary_search : (('a, [> ]) t, 'a) Binary_searchable_intf.binary_search
val binary_search_segmented : (('a, [> ]) t, 'a) Binary_searchable_intf.binary_search_segmented

These functions are in Container.S1_permissions, but they are re-exposed here so that their types can be changed to make them more permissive (see comment above).

val length : (_, _) t -> int
val is_empty : (_, _) t -> bool

counterparts of regular array functions above

external get : ('a, [> ]) t -> int -> 'a = "%array_safe_get"
external set : ('a, [> ]) t -> int -> 'a -> unit = "%array_safe_set"
external unsafe_get : ('a, [> ]) t -> int -> 'a = "%array_unsafe_get"
external unsafe_set : ('a, [> ]) t -> int -> 'a -> unit = "%array_unsafe_set"
val create : len:int -> 'a -> ('a, [< ]) t
val init : int -> f:(int -> 'a) -> ('a, [< ]) t
val make_matrix : dimx:int -> dimy:int -> 'a -> (('a, [< ]) t, [< ]) t
val append : ('a, [> ]) t -> ('a, [> ]) t -> ('a, [< ]) t
val concat : ('a, [> ]) t list -> ('a, [< ]) t
val copy : ('a, [> ]) t -> ('a, [< ]) t
val fill : ('a, [> ]) t -> pos:int -> len:int -> 'a -> unit
val of_list : 'a list -> ('a, [< ]) t
val map : f:('a -> 'b) -> ('a, [> ]) t -> ('b, [< ]) t
val iteri : f:(int -> 'a -> unit) -> ('a, [> ]) t -> unit
val mapi : f:(int -> 'a -> 'b) -> ('a, [> ]) t -> ('b, [< ]) t
val foldi : ('a, [> ]) t -> init:'b -> f:(int -> 'b -> 'a -> 'b) -> 'b
val fold_right : ('a, [> ]) t -> f:('a -> 'b -> 'b) -> init:'b -> 'b
val sort : ?pos:int -> ?len:int -> ('a, [> ]) t -> cmp:('a -> 'a -> int) -> unit
val stable_sort : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> unit
val is_sorted : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> bool
val is_sorted_strictly : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> bool
val concat_map : ('a, [> ]) t -> f:('a -> ('b, [> ]) t) -> ('b, [< ]) t
val concat_mapi : ('a, [> ]) t -> f:(int -> 'a -> ('b, [> ]) t) -> ('b, [< ]) t
val partition_tf : ('a, [> ]) t -> f:('a -> bool) -> ('a, [< ]) t * ('a, [< ]) t
val partitioni_tf : ('a, [> ]) t -> f:(int -> 'a -> bool) -> ('a, [< ]) t * ('a, [< ]) t
val cartesian_product : ('a, [> ]) t -> ('b, [> ]) t -> ('a * 'b, [< ]) t
val normalize : (_, _) t -> int -> int
val slice : ('a, [> ]) t -> int -> int -> ('a, [< ]) t
val nget : ('a, [> ]) t -> int -> 'a
val nset : ('a, [> ]) t -> int -> 'a -> unit
val filter_opt : ('a option, [> ]) t -> ('a, [< ]) t
val filter_map : ('a, [> ]) t -> f:('a -> 'b option) -> ('b, [< ]) t
val filter_mapi : ('a, [> ]) t -> f:(int -> 'a -> 'b option) -> ('b, [< ]) t
val for_alli : ('a, [> ]) t -> f:(int -> 'a -> bool) -> bool
val existsi : ('a, [> ]) t -> f:(int -> 'a -> bool) -> bool
val counti : ('a, [> ]) t -> f:(int -> 'a -> bool) -> int
val iter2_exn : ('a, [> ]) t -> ('b, [> ]) t -> f:('a -> 'b -> unit) -> unit
val map2_exn : ('a, [> ]) t -> ('b, [> ]) t -> f:('a -> 'b -> 'c) -> ('c, [< ]) t
val fold2_exn : ('a, [> ]) t -> ('b, [> ]) t -> init:'c -> f:('c -> 'a -> 'b -> 'c) -> 'c
val for_all2_exn : ('a, [> ]) t -> ('b, [> ]) t -> f:('a -> 'b -> bool) -> bool
val exists2_exn : ('a, [> ]) t -> ('b, [> ]) t -> f:('a -> 'b -> bool) -> bool
val filter : f:('a -> bool) -> ('a, [> ]) t -> ('a, [< ]) t
val filteri : f:(int -> 'a -> bool) -> ('a, [> ]) t -> ('a, [< ]) t
val swap : ('a, [> ]) t -> int -> int -> unit
val rev_inplace : ('a, [> ]) t -> unit
val of_list_rev : 'a list -> ('a, [< ]) t
val of_list_map : 'a list -> f:('a -> 'b) -> ('b, [< ]) t
val of_list_rev_map : 'a list -> f:('a -> 'b) -> ('b, [< ]) t
val replace : ('a, [> ]) t -> int -> f:('a -> 'a) -> unit
val replace_all : ('a, [> ]) t -> f:('a -> 'a) -> unit
val find_exn : ('a, [> ]) t -> f:('a -> bool) -> 'a
val find_map_exn : ('a, [> ]) t -> f:('a -> 'b option) -> 'b
val findi : ('a, [> ]) t -> f:(int -> 'a -> bool) -> (int * 'a) option
val findi_exn : ('a, [> ]) t -> f:(int -> 'a -> bool) -> int * 'a
val find_mapi : ('a, [> ]) t -> f:(int -> 'a -> 'b option) -> 'b option
val find_mapi_exn : ('a, [> ]) t -> f:(int -> 'a -> 'b option) -> 'b
val find_consecutive_duplicate : ('a, [> ]) t -> equal:('a -> 'a -> bool) -> ('a * 'a) option
val reduce : ('a, [> ]) t -> f:('a -> 'a -> 'a) -> 'a option
val reduce_exn : ('a, [> ]) t -> f:('a -> 'a -> 'a) -> 'a
val permute : ?random_state:Core_kernel.Core_random.State.t -> ('a, [> ]) t -> unit
val zip : ('a, [> ]) t -> ('b, [> ]) t -> ('a * 'b, [< ]) t option
val zip_exn : ('a, [> ]) t -> ('b, [> ]) t -> ('a * 'b, [< ]) t
val unzip : ('a * 'b, [> ]) t -> ('a, [< ]) t * ('b, [< ]) t
val sorted_copy : ('a, [> ]) t -> cmp:('a -> 'a -> int) -> ('a, [< ]) t
val last : ('a, [> ]) t -> 'a
val empty : unit -> ('a, [< ]) t
val equal : ('a, [> ]) t -> ('a, [> ]) t -> equal:('a -> 'a -> bool) -> bool
val truncate : (_, [> ]) t -> len:int -> unit
val to_sequence : ('a, [> ]) t -> 'a Core_kernel.Sequence.t
val to_sequence_mutable : ('a, [> ]) t -> 'a Core_kernel.Sequence.t