Hi,

I'd like to be able to do replicateM, but over a vector instead of a list. 
Right now I'm doing this:
 
import qualified Data.Vector.Generic as G
import qualified Data.Vector.Unboxed.Mutable as M
replicateM n action = do
  mu <- M.unsafeNew n
  let go !i | i < n = action >>= M.unsafeWrite mu i >> go (i+1)
             | otherwise = G.unsafeFreeze mu
  go 0

I thought it might be useful to express this in terms of the available 
primitives, since this might fuse more easily, but I don't yet see a way to do 
it.

Is there a better (more elegant and/or faster) way to write this?

Thanks,
Chad
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to