Closed chessai closed 5 years ago
@andrewthad what are your thoughts on this and the related issue?
Related issue is #8
This PR is mostly good but still has some things a little bit off. Notably, replicateM
is misnamed. I think the names we actually want are:
replicate :: (Contiguous arr, Element arr b) => Int -> b -> arr b
replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b)
replicateMutableM :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m b -> m (Mutable arr (PrimState m) b)
Now, the other important question is which ones of these actually need to be typeclass methods. We need replicateMutable
in the typeclass because array initialization works differently for the lifted and unlifted array types. However, replicate n x = runST (replicateMutable n x >>= unsafeFreeze)
, which cannot be improved upon for any of the array types, so it doesn't need to be in there. We can kick out replicateMutableM
as well since it is always implemented as: 1. create an array of unitialized elements 2. loop with the monadic generator to produce each element.
suggested changes have been made
now we have
replicate
,replicateMutable
, andreplicateM
inContiguous
.I feel that this is more consistent with the rest of the ecosystem.