Module Shared.Local

Functions to work with ('a, 'k) t @ local.

val wrap : access:'k Access.t @ shared -> 'a @ local -> ('a, 'k) t @ local @@ portable

wrap ~access v returns a pointer to the local value v, which lives in the sub-capsule of 'k. 'k is always the current capsule.

val unwrap : access:'k Access.t @ shared -> ('a, 'k) t @ local -> 'a @ local @@ portable

unwrap ~access t returns the value of t, which lives in the sub-capsule of 'k. 'k is always the current capsule.

val create : (unit -> 'a @ local) @ local once portable -> ('a, 'k) t @ local @@ portable

create f runs f within the sub-capsule of 'k and returns a local pointer to the result.

val map : password:'k Password.Shared.t @ local -> (f:('a @ local -> 'b @ local) @ local once portable -> (('a, 'k) t @ local -> ('b, 'k) t @ local) @ local once) @ local @@ portable

map ~pasword ~f t applies f to the value of p within the sub-capsule of 'k and returns a local pointer to the result.

val both : ('a, 'k) t @ local -> (('b, 'k) t @ local -> ('a * 'b, 'k) t @ local) @ local @@ portable

both t1 t2 is a pointer to a pair of the values of t1 and t2.

val fst : ('a * 'b, 'k) t @ local -> ('a, 'k) t @ local @@ portable

fst t gives a pointer to the first value inside t

val snd : ('a * 'b, 'k) t @ local -> ('b, 'k) t @ local @@ portable

snd t gives a pointer to the second value inside t

val extract : password:'k Password.Shared.t @ local -> (f: ('a @ local -> 'b @ local unique once portable contended) @ local once portable -> (('a, 'k) t @ local -> 'b @ local unique once portable contended) @ local once) @ local @@ portable

extract ~pasword ~f t applies f to the value of t within the sub-capsule of 'k and returns the result. The result has access to 'k so must be portable and is marked contended.

val inject : 'a 'k. 'a @ local portable -> ('a, 'k) t @ local @@ portable

inject v is a pointer to an value v injected into the capsule 'k. It's a specialization of create to values that are always uncontended.

val project : 'a 'k. ('a, 'k) t @ local -> 'a @ local contended @@ portable

project t returns the value of t. The result is within 'k, so must be portable and is marked contended. Since it's always portable, unlike with extract, we don't need exclusive access to 'k: all accesses to the value happen only after it's marked contended.

val bind : password:'k Password.Shared.t @ local -> (f:('a @ local -> ('b, 'j) t @ local) @ local once portable -> (('a, 'k) t @ local -> ('b, 'j) t @ local) @ local once) @ local @@ portable

bind ~password ~f t is project (map ~password ~f t).

val iter : password:'k Password.Shared.t @ local -> (f:('a @ local -> unit) @ local once portable -> (('a, 'k) t @ local -> unit) @ local once) @ local @@ portable

iter is extract with result type specialized to unit.

val map_into : 'a 'b 'k. password:'k Password.Shared.t @ local -> (f:('a @ local shared -> 'b @ local) @ local once portable -> (('a, 'k) data @ local -> ('b, 'k) t @ local) @ local once) @ local @@ portable

map_into is like Capsule.map_shared but returns a Shared.t.