简体   繁体   中英

Mutable vector: clear reference at given index

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 ()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM