@@ -351,15 +351,23 @@ pub inline extern ref/(!)<h,a,e>( ref : ref<h,a>, ?hdiv : hdiv<h,a,e>) : <read<h
351351 cs inline "#1.Value "
352352 js inline "#1.value "
353353
354- // Modify the value of a reference.
355- // This is especially useful when the reference contains a vector, because
354+ // Access the value of a reference, by evaluating a function with the reference as a local-var.
355+ // Assigning to this var within the block using `:=` will modify the underlying reference.
356+ //
357+ // e.g. `counter.access(fn(i) { i := i + 1 })`
358+ //
359+ // This function is especially useful when the reference contains a vector, because
356360// getting the vector into a local variable and then setting it back into the reference later
357361// would mean that we hold on to a copy (and we can't update the vector in place then!).
358362// In contrast, this function passes the ownership to the given function.
359- pub inline extern modify < h, a, b, e> ( ref : ref < h, a> , f : forall < s> local-var < s, a> -> < local < s> |e> b, ? hdiv : hdiv < h, a, e> ) : < read < h> ,write < h> |e> b
360- c inline "kk_ref_modify (#1,#2,kk_context()) "
363+ pub inline extern access < h, a, b, e> ( ref : ref < h, a> , f : forall < s> local-var < s, a> -> < local < s> |e> b, ? hdiv : hdiv < h, a, e> ) : < read < h> ,write < h> |e> b
364+ c inline "kk_ref_access (#1,#2,kk_context()) "
361365 js inline "((#2)(#1)) "
362366
367+ // Deprecated: alias for `access`
368+ pub inline extern modify < h, a, b, e> ( ref : ref < h, a> , f : forall < s> local-var < s, a> -> < local < s> |e> b, ? hdiv : hdiv < h, a, e> ) : < read < h> ,write < h> |e> b
369+ c "kk_ref_access "
370+
363371// If a heap effect is unobservable, the heap effect can be erased by using the `run` fun.
364372// See also: _State in Haskell, by Simon Peyton Jones and John Launchbury_.
365373pub extern run < e, a> ( action : forall < h> () -> < alloc < h> ,read < h> ,write < h> | e> a ) : e a
0 commit comments