Are ref cells like pointers in the sense that they reference data on the heap, and need to be explicitly deleted? All the examples I've seen online don't have explicit delete calls.
How would you delete them explicitly?
Also if you take a look at the source code you'll see that ref cell type is just an immutable wrapper over a mutable field, and the :=
and !
operators are simply getter/setter calls.
You can implement ref in a similar way yourself quite easily:
type Ref<'a> = { mutable value: 'a }
let (:=) (r: Ref<_>) v = r.value <- v
let (!) (r: Ref<_>) = r.value
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With