In C++, std::vector constructor takes unsigned integer, where negative integers overflow. It leads to runtime error and negative size to constructors are surely invalid.
In our vector, however, they die at negative sizes on new, but not on replicate:
replicate :: (PrimMonad m, MVector v a) => Int -> a -> m (v (PrimState m) a)
{-# INLINE replicate #-}
replicate n x = stToPrim $ basicUnsafeReplicate (delay_inline max 0 n) x
Should we emit error when given negative size to constructors?
In C++,
std::vector
constructor takes unsigned integer, where negative integers overflow. It leads to runtime error and negative size to constructors are surely invalid.In our
vector
, however, they die at negative sizes onnew
, but not onreplicate
:Should we emit
error
when given negative size to constructors?