With one modification (below).
In summary, this proposal suggests adding primitives for resizing (shrinking or expanding) primitives mutable arrays of pointers. See the proposal for motivation. There would be two primitives per array type:
shrinkArray# :: MutableArray# s a -> Int# -> State# s -> State# s
resizeArray# :: MutableArray# s a -> Int# -> a -> State# s -> (# State# s, MutableArray# s a #)
(these mirror the existing shrink and resize primitives we have for ByteArray#, with the same rationale)
The biggest downside is that we currently have
sizeOfMutableArray# :: MutableArray# s a -> Int #
which would need to be replaced by a stateful operation
getSizeOfMutableArray# :: MutableArray# s a -> State# s -> (# State# s, Int# #)
So we would need to deprecate the old primops, update any code we have that uses them, and clearly indicate the unsafety in the docs. But this has knock-on effects in Data.Primitive:
sizeofMutableArray :: MutableArray s a -> Int
this would need to be deprecated and replaced by a PrimMonad operation. The pure version would be unsafe in the sense that it could return the wrong size, and a future indexing operation relying on the incorrect size could access an out-of-bounds element.
Suggested modifications: