Module BatArray.Cap

module Cap: sig .. end
Capabilities for arrays.

This modules provides the same set of features as Array, but with the added twist that arrays can be made read-only or write-only. Read-only arrays may then be safely shared and distributed.

There is no loss of performance involved.


Only the capability-specific functions are documented here. See the complete Array module for the documentation of other functions.

type ('a, [< `Read | `Write ]) t 

The type of arrays with capabilities. An ('a, [`Read | `Write]) array behaves as a regular 'a array, while a ('a, [`Read]) array only has read-only capabilities and a ('a, [`Write]) array only has write-only capabilities.

Base operations
val length : ('a, [< `Read | `Write ]) t -> int
val get : ('a, [< `Read | `Write > `Read ]) t -> int -> 'a
val set : ('a, [< `Read | `Write > `Write ]) t -> int -> 'a -> unit
Constructors
val make : int -> 'a -> ('a, [< `Read | `Write ]) t
val create : int -> 'a -> ('a, [< `Read | `Write ]) t
val make_float : int -> (float, [< `Read | `Write ]) t

Array.make_float n returns a fresh float array of length n, with uninitialized data.

val of_array : 'a array -> ('a, [< `Read | `Write ]) t

Adopt a regular array as a capability array, allowing to decrease capabilities if necessary.

This operation involves no copying. In other words, in let cap = of_array a in ..., any modification in a will also have effect on cap and reciprocally.

val to_array : ('a, [ `Read | `Write ]) t -> 'a array

Return a capability array as an array.

This operation requires both read and write permissions on the capability array and involves no copying. In other words, in let a = of_array cap in ..., any modification in a will also have effect on cap and reciprocally.

val read_only : ('a, [< `Read | `Write > `Read ]) t ->
('a, [ `Read ]) t

Drop to read-only permissions.

This operation involves no copying.

val write_only : ('a, [< `Read | `Write > `Write ]) t ->
('a, [ `Write ]) t

Drop to write-only permissions.

This operation involves no copying.

val init : int -> (int -> 'a) -> ('a, [< `Read | `Write ]) t
val make_matrix : int ->
int ->
'a ->
(('a, [< `Read | `Write ]) t, [< `Read | `Write ])
t
val create_matrix : int ->
int ->
'a ->
(('a, [< `Read | `Write ]) t, [< `Read | `Write ])
t
Iterators
val iter : ('a -> unit) -> ('a, [< `Read | `Write > `Read ]) t -> unit
val map : ('a -> 'b) ->
('a, [< `Read | `Write > `Read ]) t ->
('b, [< `Read | `Write ]) t
val iteri : (int -> 'a -> unit) ->
('a, [< `Read | `Write > `Read ]) t -> unit
val mapi : (int -> 'a -> 'b) ->
('a, [< `Read | `Write > `Read ]) t ->
('b, [< `Read | `Write ]) t
val modify : ('a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val modifyi : (int -> 'a -> 'a) -> ('a, [ `Read | `Write ]) t -> unit
val fold_left : ('a -> 'b -> 'a) ->
'a -> ('b, [< `Read | `Write > `Read ]) t -> 'a
val fold : ('a -> 'b -> 'a) ->
'a -> ('b, [< `Read | `Write > `Read ]) t -> 'a
val fold_right : ('b -> 'a -> 'a) ->
('b, [< `Read | `Write > `Read ]) t -> 'a -> 'a
val fold_while : ('acc -> 'a -> bool) ->
('acc -> 'a -> 'acc) ->
'acc -> ('a, [< `Read | `Write > `Read ]) t -> 'acc * int
Operations on two arrays
val iter2 : ('a -> 'b -> unit) ->
('a, [< `Read | `Write > `Read ]) t ->
('b, [< `Read | `Write > `Read ]) t -> unit
val iter2i : (int -> 'a -> 'b -> unit) ->
('a, [< `Read | `Write > `Read ]) t ->
('b, [< `Read | `Write > `Read ]) t -> unit
Predicates
val for_all : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> bool
val exists : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> bool
val find : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> 'a
val mem : 'a -> ('a, [< `Read | `Write > `Read ]) t -> bool
val memq : 'a -> ('a, [< `Read | `Write > `Read ]) t -> bool
val findi : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> int
val filter : ('a -> bool) ->
('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t
val filter_map : ('a -> 'b option) ->
('a, [< `Read | `Write > `Read ]) t ->
('b, [< `Read | `Write ]) t
val count_matching : ('a -> bool) -> ('a, [< `Read | `Write > `Read ]) t -> int
val find_all : ('a -> bool) ->
('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t
val partition : ('a -> bool) ->
('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t *
('a, [< `Read | `Write ]) t
Array transformations
val rev : ('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t
val rev_in_place : ('a, [ `Read | `Write ]) t -> unit
val append : ('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t
val concat : ('a, [< `Read | `Write > `Read ]) t list ->
('a, [< `Read | `Write ]) t
val sub : ('a, [< `Read | `Write > `Read ]) t ->
int -> int -> ('a, [< `Read | `Write ]) t
val copy : ('a, [< `Read | `Write > `Read ]) t -> 'a array
val fill : ('a, [< `Read | `Write > `Write ]) t -> int -> int -> 'a -> unit
val blit : ('a, [< `Read | `Write > `Read ]) t ->
int ->
('a, [< `Read | `Write > `Write ]) t -> int -> int -> unit
Conversions
val enum : ('a, [< `Read | `Write > `Read ]) t -> 'a BatEnum.t
val of_enum : 'a BatEnum.t -> ('a, [< `Read | `Write ]) t
val backwards : ('a, [< `Read | `Write > `Read ]) t -> 'a BatEnum.t
val of_backwards : 'a BatEnum.t -> ('a, [< `Read | `Write ]) t
val to_list : ('a, [< `Read | `Write > `Read ]) t -> 'a list
val split : ('a * 'b, [< `Read | `Write > `Read ]) t ->
('a, [< `Read | `Write ]) t *
('b, [< `Read | `Write ]) t
val pivot_split : 'a BatOrd.ord ->
('a, [< `Read | `Write > `Read ]) t -> 'a -> int * int
val of_list : 'a list -> ('a, [< `Read | `Write ]) t
Utilities
val sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
val stable_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
val fast_sort : ('a -> 'a -> int) -> ('a, [ `Read | `Write ]) t -> unit
Boilerplate code
val print : ?first:string ->
?last:string ->
?sep:string ->
('a BatIO.output -> 'b -> unit) ->
'a BatIO.output -> ('b, [< `Read | `Write > `Read ]) t -> unit
val compare : 'a BatOrd.comp ->
('a, [< `Read | `Write > `Read ]) t BatOrd.comp
val ord : 'a BatOrd.ord -> ('a, [< `Read | `Write > `Read ]) t BatOrd.ord
val equal : 'a BatOrd.eq -> ('a, [< `Read | `Write > `Read ]) t BatOrd.eq
Override modules
module Exceptionless: sig .. end

Operations on BatArray.Cap without exceptions.

module Labels: sig .. end

Operations on BatArray.Cap with labels.