I have a type that encapsulates a key to an external resource. Once the key is lost (all values that share it get out of scope), the resource should be released (implicitly) on the next garbage-collection, like memory does for regular values.
So I'm looking for something similar to OOP disposing, or ForeignPtr
, only that I represent references to something other than objects from foreign languages (although if ForeignPtr
can properly and elegantly work for this too, knowing how would also answer this question).
Is it possible? if so, how?
I suggest you look at ResourceT:
ResourceT is a monad transformer which creates a region of code where you can safely allocate resources.
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