@@ -455,7 +455,10 @@ byteLength Array{..} =
455-- @since 0.7.0
455-- @since 0.7.0
456{-# INLINE length #-}
456{-# INLINE length #-}
457length :: forall a. Storable a => Array a -> Int
457length :: forall a. Storable a => Array a -> Int
458−length arr = byteLength arr `div` sizeOf (undefined :: a)
459+ let elemSize = sizeOf (undefined :: a)
460+ blen = byteLength arr
461+ in assert (blen `mod` elemSize == 0) (blen `div` elemSize)
460-- | Get the total capacity of an array. An array may have space reserved
463-- | Get the total capacity of an array. An array may have space reserved
461-- beyond the current used length of the array.
464-- beyond the current used length of the array.