Is there a similar idiom to this that works with ‘cloptr’ to avoid use of
the garbage collector, assuming a ‘linset’ that takes a cloptr instead of a
cloref?
Code I’ve written in the past does something like:
absviewtype myset
fun myset_make_nil (): myset
fun myset_is_member (a: !myset, x: int): bool
local
viewtypedef myset_struct = @{ s= set (int), cmp= (int,int) - int }
assume myset = [l:addr] @{ pf= myset_struct @ l, p= ptr l}
in
implement myset_make_nil () = let
val s = linset_make_nil ()
val c = lam (a,b) = compare_int_int (a,b)
val (pf1, pf2 | p) = ptr_alloc<myset_struct> ()
prval () = __foo (pf1) where {
extern prfun __foo {l:agz} (x: free_gc_v (myset_struct?, l
)): void
}
val () = !p.cmp := c
val () = !p.s := s
in
@{ pf= pf2, p= p }
end
implement myset_is_member (a, x): bool = let
prval pf = a.pf
val b = linset_is_member (a.p->s, x, a.p->cmp)
prval () = a.pf := pf
in
b
end
end
Is this a reasonable approach?