byteverse / contiguous

Typeclass for array types
Other
18 stars 8 forks source link

replicateM is a misnomer #8

Closed chessai closed 5 years ago

chessai commented 5 years ago

replicateM usually looks like:

replicateM :: Monad m => Int -> m a -> m [a]
replicateM = ...

it executes the monadic action n times, and stores the result for each time. This is semantically different from the replicateM in Contiguous, because no action is executed - the second argument is a pure value.

replicateM :: (PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b)

I would think that to most users this would be confusing, because of most APIs using the semantics of the former for replicateM. I propose that we do the following:

  1. change replicateM to replicateM :: Int -> m b -> m (Mutable arr (PrimState m) b)
  2. add replicate :: Int -> b -> arr b.