Reputation: 1309
I understand that the vector provides a mutable interface which includes the clear
function, clearing references to all the objects stored in the vector. I can't find a similar function that would clear the reference stored at index n
in the vector. Is there any way to achieve such a thing, and if not, why?
NB: The function would look something like this:
clearAtIndex :: MVector (PrimState m) a -> Int -> m ()
Upvotes: 0
Views: 55
Reputation: 105965
There's nothing like that in the package itself, but one can use the same implementation as clear
:
clearAtIndex :: MVector (PrimState m) a -> Int -> m ()
clearAtIndex v n = write v n uninitialised
uninitialised :: a
uninitialised = error "clearAtIndex: uninitialised element"
clear
basically works the same, but uses set v uninitialised
in order to use possible optimizations.
Upvotes: 4