Skip to content

Commit 32928c9

Browse files
committed
rename ref.modify -> ref.access
1 parent 00399ab commit 32928c9

File tree

4 files changed

+15
-7
lines changed

4 files changed

+15
-7
lines changed

kklib/include/kklib/ref.h

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ static inline kk_unit_t kk_ref_set_borrow(kk_ref_t r, kk_box_t value, kk_context
8484
}
8585

8686
// In Koka we can constrain the argument of f to be a local-scope reference.
87-
static inline kk_box_t kk_ref_modify(kk_ref_t r, kk_function_t f, kk_context_t* ctx) {
87+
static inline kk_box_t kk_ref_access(kk_ref_t r, kk_function_t f, kk_context_t* ctx) {
8888
return kk_function_call(kk_box_t,(kk_function_t,kk_ref_t,kk_context_t*),f,(f,r,ctx),ctx);
8989
}
9090

lib/std/core/types.kk

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -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_.
365373
pub extern run<e,a>( action : forall<h> () -> <alloc<h>,read<h>,write<h> | e> a ) : e a
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fun main() {
22
val r = ref(0)
3-
r.modify( fn(l) l := 1 )
3+
r.access( fn(l) l := 1 )
44
(!r).println
5-
}
5+
}

0 commit comments

Comments
 (0)