Data.LocalFunctions to work with ('a, 'k) t @ local.
wrap ~access v returns a pointer to the local value v, which lives in the capsule 'k. 'k is always the current capsule.
unwrap ~access t returns the value of t, which lives in the capsule 'k. 'k is always the current capsule.
Like wrap, but for unique values.
val unwrap_unique :
access:'k Access.t ->
('a, 'k) t @ local unique ->
'a @ local unique @@ portableLike unwrap, but for unique values.
Like wrap, but for once values.
Like unwrap, but for once values.
unwrap_shared ~access t returns the shared value of t, which lives in the capsule 'k. 'k is always the current capsule. Since 'a may have been shared with other threads, 'a must cross portability.
val create :
(unit -> 'a @ local) @ local once portable ->
('a, 'k) t @ local @@ portablecreate f runs f within the capsule 'k and returns a local pointer to the result of f.
val map :
password:'k Password.t @ local ->
(f:('a @ local -> 'b @ local) @ local once portable ->
(('a, 'k) t @ local ->
('b, 'k) t @ local) @ local once) @ local @@ portablemap ~password ~f t applies f to the value of p within the capsule '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 @@ portableboth t1 t2 is a pointer to a pair of the values of t1 and t2.
fst t gives a pointer to the first value inside t
snd t gives a pointer to the second value inside t
val extract :
password:'k Password.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 @@ portableextract ~password ~f t applies f to the value of t within the capsule 'k and returns the result. The result is within 'k so must be portable and is marked contended.
val inject : 'a 'k. 'a @ local portable -> ('a, 'k) t @ local @@ portableinject 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 @@ portableproject 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.
project_shared ~key t is like project t, but since t is a capsule associated with a key @ aliased global, the contents can be returned at shared.
val bind :
password:'k Password.t @ local ->
(f:('a @ local -> ('b, 'j) t @ local) @ local once portable ->
(('a, 'k) t @ local ->
('b, 'j) t @ local) @ local once) @ local @@ portablebind ~password ~f t is project (map ~password ~f t).
val iter :
password:'k Password.t @ local ->
(f:('a @ local -> unit) @ local once portable ->
(('a, 'k) t @ local ->
unit) @ local once) @ local @@ portableiter is extract with result type specialized to unit.
map_shared ~password ~f t applies f to the shared parts of t within the capsule 'k and returns a pointer to the result. Since 'a may have been shared with other threads, 'a must cross portability.
extract_shared ~password ~f t applies f to the shared parts of t within the capsule 'k and returns the result. The result is within 'k so must be portable and is marked contended. Since 'a may have been shared with other threads, 'a must cross portability.