module Permissioned:sig
..end
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.type ('a, -'perms)
t
'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.module Int:sig
..end
module Float:sig
..end
val of_array_id : 'a array -> ('a, [< Perms.Export.read_write ]) 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:
'a Array.t = 'a array
for interoperability with code which
does not use Core.('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, [> Perms.Export.read_write ]) t -> 'a array
val to_sequence_immutable : ('a, [> Perms.Export.immutable ]) t -> 'a 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 Container.S1_permissions
include Blit.S1_permissions
include Binary_searchable.S1_permissions
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 : ('a, 'b) t -> int
val is_empty : ('a, 'b) t -> bool
val get : ('a, [> Perms.Export.read ]) t -> int -> 'a
val set : ('a, [> Perms.Export.write ]) t -> int -> 'a -> unit
val unsafe_get : ('a, [> Perms.Export.read ]) t -> int -> 'a
val unsafe_set : ('a, [> Perms.Export.write ]) t -> int -> 'a -> unit
val create : len:int -> 'a -> ('a, [< 'b Perms.Export.perms ]) t
val init : int ->
f:(int -> 'a) -> ('a, [< 'b Perms.Export.perms ]) t
val make_matrix : dimx:int ->
dimy:int ->
'a ->
(('a, [< 'b Perms.Export.perms ]) t,
[< 'c Perms.Export.perms ])
t
val append : ('a, [> Perms.Export.read ]) t ->
('a, [> Perms.Export.read ]) t ->
('a, [< 'b Perms.Export.perms ]) t
val concat : ('a, [> Perms.Export.read ]) t list ->
('a, [< 'b Perms.Export.perms ]) t
val copy : ('a, [> Perms.Export.read ]) t ->
('a, [< 'b Perms.Export.perms ]) t
val fill : ('a, [> Perms.Export.write ]) t ->
pos:int -> len:int -> 'a -> unit
val of_list : 'a list -> ('a, [< 'b Perms.Export.perms ]) t
val map : f:('a -> 'b) ->
('a, [> Perms.Export.read ]) t ->
('b, [< 'c Perms.Export.perms ]) t
val iteri : f:(int -> 'a -> unit) ->
('a, [> Perms.Export.read ]) t -> unit
val mapi : f:(int -> 'a -> 'b) ->
('a, [> Perms.Export.read ]) t ->
('b, [< 'c Perms.Export.perms ]) t
val foldi : ('a, [> Perms.Export.read ]) t ->
init:'b -> f:(int -> 'b -> 'a -> 'b) -> 'b
val fold_right : ('a, [> Perms.Export.read ]) t ->
f:('a -> 'b -> 'b) -> init:'b -> 'b
val sort : ?pos:int ->
?len:int ->
('a, [> Perms.Export.read_write ]) t ->
cmp:('a -> 'a -> int) -> unit
val stable_sort : ('a, [> Perms.Export.read_write ]) t ->
cmp:('a -> 'a -> int) -> unit
val is_sorted : ('a, [> Perms.Export.read ]) t ->
cmp:('a -> 'a -> int) -> bool
val is_sorted_strictly : ('a, [> Perms.Export.read ]) t ->
cmp:('a -> 'a -> int) -> bool
val concat_map : ('a, [> Perms.Export.read ]) t ->
f:('a -> ('b, [> Perms.Export.read ]) t) ->
('b, [< 'c Perms.Export.perms ]) t
val partition_tf : ('a, [> Perms.Export.read ]) t ->
f:('a -> bool) ->
('a, [< 'b Perms.Export.perms ]) t *
('a, [< 'c Perms.Export.perms ]) t
val partitioni_tf : ('a, [> Perms.Export.read ]) t ->
f:(int -> 'a -> bool) ->
('a, [< 'b Perms.Export.perms ]) t *
('a, [< 'c Perms.Export.perms ]) t
val cartesian_product : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
('a * 'b, [< 'c Perms.Export.perms ]) t
val normalize : ('a, 'b) t -> int -> int
val slice : ('a, [> Perms.Export.read ]) t ->
int -> int -> ('a, [< 'b Perms.Export.perms ]) t
val nget : ('a, [> Perms.Export.read ]) t -> int -> 'a
val nset : ('a, [> Perms.Export.write ]) t -> int -> 'a -> unit
val filter_opt : ('a option, [> Perms.Export.read ]) t ->
('a, [< 'b Perms.Export.perms ]) t
val filter_map : ('a, [> Perms.Export.read ]) t ->
f:('a -> 'b option) ->
('b, [< 'c Perms.Export.perms ]) t
val filter_mapi : ('a, [> Perms.Export.read ]) t ->
f:(int -> 'a -> 'b option) ->
('b, [< 'c Perms.Export.perms ]) t
val iter2_exn : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
f:('a -> 'b -> unit) -> unit
val map2_exn : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
f:('a -> 'b -> 'c) ->
('c, [< 'd Perms.Export.perms ]) t
val fold2_exn : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
init:'c -> f:('c -> 'a -> 'b -> 'c) -> 'c
val for_all2_exn : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
f:('a -> 'b -> bool) -> bool
val filter : f:('a -> bool) ->
('a, [> Perms.Export.read ]) t ->
('a, [< 'b Perms.Export.perms ]) t
val filteri : f:(int -> 'a -> bool) ->
('a, [> Perms.Export.read ]) t ->
('a, [< 'b Perms.Export.perms ]) t
val swap : ('a, [> Perms.Export.read_write ]) t ->
int -> int -> unit
val rev_inplace : ('a, [> Perms.Export.read_write ]) t -> unit
val of_list_rev : 'a list -> ('a, [< 'b Perms.Export.perms ]) t
val of_list_map : 'a list ->
f:('a -> 'b) -> ('b, [< 'c Perms.Export.perms ]) t
val of_list_rev_map : 'a list ->
f:('a -> 'b) -> ('b, [< 'c Perms.Export.perms ]) t
val replace : ('a, [> Perms.Export.read_write ]) t ->
int -> f:('a -> 'a) -> unit
val replace_all : ('a, [> Perms.Export.read_write ]) t ->
f:('a -> 'a) -> unit
val find_exn : ('a, [> Perms.Export.read ]) t ->
f:('a -> bool) -> 'a
val findi : ('a, [> Perms.Export.read ]) t ->
f:(int -> 'a -> bool) -> (int * 'a) option
val findi_exn : ('a, [> Perms.Export.read ]) t ->
f:(int -> 'a -> bool) -> int * 'a
val find_consecutive_duplicate : ('a, [> Perms.Export.read ]) t ->
equal:('a -> 'a -> bool) -> ('a * 'a) option
val reduce : ('a, [> Perms.Export.read ]) t ->
f:('a -> 'a -> 'a) -> 'a option
val reduce_exn : ('a, [> Perms.Export.read ]) t ->
f:('a -> 'a -> 'a) -> 'a
val permute : ?random_state:Core_random.State.t ->
('a, [> Perms.Export.read_write ]) t -> unit
val combine : ('a, [> Perms.Export.read ]) t ->
('b, [> Perms.Export.read ]) t ->
('a * 'b, [< 'c Perms.Export.perms ]) t
val split : ('a * 'b, [> Perms.Export.read ]) t ->
('a, [< 'c Perms.Export.perms ]) t *
('b, [< 'd Perms.Export.perms ]) t
val sorted_copy : ('a, [> Perms.Export.read ]) t ->
cmp:('a -> 'a -> int) ->
('a, [< 'b Perms.Export.perms ]) t
val last : ('a, [> Perms.Export.read ]) t -> 'a
val empty : unit -> ('a, [< 'b Perms.Export.perms ]) t
val equal : ('a, [> Perms.Export.read ]) t ->
('a, [> Perms.Export.read ]) t ->
equal:('a -> 'a -> bool) -> bool
val truncate : ('a, [> Perms.Export.write ]) t -> len:int -> unit
module Infix:sig
..end
val to_sequence : ('a, [> Perms.Export.read ]) t -> 'a Sequence.t
val to_sequence_mutable : ('a, [> Perms.Export.read ]) t -> 'a Sequence.t
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_reader_t : 'a Bin_prot.Type_class.reader ->
'perms Bin_prot.Type_class.reader ->
('a, 'perms) t Bin_prot.Type_class.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
val bin_writer_t : 'a Bin_prot.Type_class.writer ->
'perms Bin_prot.Type_class.writer ->
('a, 'perms) t Bin_prot.Type_class.writer
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:
'a Array.t = 'a array
for interoperability with code which
does not use Core.('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.
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.
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).
counterparts of regular array functions above