
1 Apr
2010
1 Apr
'10
5:48 p.m.
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