There were quite a few proposal to enrich API of mutable vectors: #326, #203, #64, #175. Tris issue tries to collect all proposals from them in one nice list (and adds few on top of them)
Folds & lookup
I'm not sure that foldlM_ & friends are worth adding. It's easy to ignore return result of fold anyway: void, _ <- .... It however could be useful to add pure variants:
They come with performance bonus. We can perform entire fold in the ST monad and only lift to m at last moment. This way GHC only have to use bind from ST monad and it's good at optimizing it
In place mutation
Naming could be slightly confusing here. Should in place map be called mapM or mapM_. Underscore usually means throwing away results of function and mapM builds new structure. I'm slightly lean towards mapM since it's in-place map
Creation
Comments? Objections? Proposals?
There were quite a few proposal to enrich API of mutable vectors: #326, #203, #64, #175. Tris issue tries to collect all proposals from them in one nice list (and adds few on top of them)
Folds & lookup
foldlM :: (b -> a -> m b) -> b -> v s a -> m bfoldrM :: (a -> b -> m b) -> b -> v s a -> m bmapM_ :: (a -> m ()) -> v s a -> m ()/forM_imapM_ :: (Int -> a -> m ()) -> v s a -> m ()/forM_ifoldlM/ifoldrMelemIndexI'm not sure that
foldlM_& friends are worth adding. It's easy to ignore return result of fold anyway:void,_ <- .... It however could be useful to add pure variants:foldl :: (b -> a -> b) -> b -> v s a -> m bfoldr :: (a -> b -> b) -> b -> v s a -> m bThey come with performance bonus. We can perform entire fold in the ST monad and only lift to
mat last moment. This way GHC only have to use bind from ST monad and it's good at optimizing itIn place mutation
Naming could be slightly confusing here. Should in place map be called
mapMormapM_. Underscore usually means throwing away results of function andmapMbuilds new structure. I'm slightly lean towardsmapMsince it's in-place mapmapM :: (a -> m a) -> v s a -> m ()/forMmap :: (a -> a) -> v s a -> m ()/ forimap :: (Int -> a -> a) -> v s a -> m ()/ iforimapM :: (Int -> a -> m a) -> v s a -> m ()/iforMmodifyM :: v s a -> (a -> m a) -> Int -> m ()previousPermutation :: (PrimMonad m, Ord e, MVector v e) => v (PrimState m) e -> m Bool(to complement nextPermutation)reverseCreation
generate :: Int -> (Int -> a) -> m (v s a)generateM :: Int -> (Int -> m a) -> m (v s a)Comments? Objections? Proposals?