@@ -251,8 +251,8 @@ newArray n@(I# n#) =
252-- /Pre-release/
252-- /Pre-release/
253{-# INLINE putIndexUnsafe #-}
253{-# INLINE putIndexUnsafe #-}
254−putIndexUnsafe :: forall m a. MonadIO m => Array a -> Int -> a -> m ()
254+putIndexUnsafe :: forall m a. MonadIO m => Int -> a -> Array a -> m ()
255−putIndexUnsafe Array {..} i x =
255+putIndexUnsafe i x Array {..} =
@@ -268,14 +268,14 @@ invalidIndex label i =
268-- | /O(1)/ Write the given element at the given index in the array.
268-- | /O(1)/ Write the given element at the given index in the array.
269-- Performs in-place mutation of the array.
269-- Performs in-place mutation of the array.
271−-- >>> putIndex arr ix val = Array.modifyIndex arr ix (const (val, ()))
271+-- >>> putIndex ix val arr = Array.modifyIndex ix (const (val, ())) arr
273-- /Pre-release/
273-- /Pre-release/
274{-# INLINE putIndex #-}
274{-# INLINE putIndex #-}
275−putIndex :: MonadIO m => Array a -> Int -> a -> m ()
275+putIndex :: MonadIO m => Int -> a -> Array a -> m ()
276−putIndex arr@Array {..} i x =
276+putIndex i x arr@Array {..} =
277 if i >= 0 && i < arrLen
277 if i >= 0 && i < arrLen
278− then putIndexUnsafe arr i x
278+ then putIndexUnsafe i x arr
279 else invalidIndex "putIndex" i
279 else invalidIndex "putIndex" i
281-- | Modify a given index of an array using a modifier function without checking
281-- | Modify a given index of an array using a modifier function without checking
@@ -284,8 +284,8 @@ putIndex arr@Array {..} i x =
284-- Unsafe because it does not check the bounds of the array.
284-- Unsafe because it does not check the bounds of the array.
286-- /Pre-release/
286-- /Pre-release/
287−modifyIndexUnsafe :: MonadIO m => Array a -> Int -> (a -> (a, b)) -> m b
287+modifyIndexUnsafe :: MonadIO m => Int -> (a -> (a, b)) -> Array a -> m b
288−modifyIndexUnsafe Array {..} i f = do
288+modifyIndexUnsafe i f Array {..} = do
@@ -300,10 +300,10 @@ modifyIndexUnsafe Array {..} i f = do
300-- | Modify a given index of an array using a modifier function.
300-- | Modify a given index of an array using a modifier function.
302-- /Pre-release/
302-- /Pre-release/
303−modifyIndex :: MonadIO m => Array a -> Int -> (a -> (a, b)) -> m b
303+modifyIndex :: MonadIO m => Int -> (a -> (a, b)) -> Array a -> m b
304−modifyIndex arr@Array {..} i f = do
304+modifyIndex i f arr@Array {..} = do
305 if i >= 0 && i < arrLen
305 if i >= 0 && i < arrLen
306− then modifyIndexUnsafe arr i f
306+ then modifyIndexUnsafe i f arr
307 else invalidIndex "modifyIndex" i
307 else invalidIndex "modifyIndex" i
309-------------------------------------------------------------------------------
309-------------------------------------------------------------------------------
@@ -362,7 +362,7 @@ reallocWith label sizer reqSize arr = do
362snocUnsafe :: MonadIO m => Array a -> a -> m (Array a)
362snocUnsafe :: MonadIO m => Array a -> a -> m (Array a)
363snocUnsafe arr@Array {..} a = do
363snocUnsafe arr@Array {..} a = do
364 assert (arrStart + arrLen < arrTrueLen) (return ())
364 assert (arrStart + arrLen < arrTrueLen) (return ())
365− putIndexUnsafe arr arrLen a
365+ putIndexUnsafe arrLen a arr
366 return $ arr {arrLen = arrLen + 1}
366 return $ arr {arrLen = arrLen + 1}
368-- NOINLINE to move it out of the way and not pollute the instruction cache.
368-- NOINLINE to move it out of the way and not pollute the instruction cache.
@@ -417,8 +417,8 @@ snoc = snocWith (* 2)
418-- Unsafe because it does not check the bounds of the array.
418-- Unsafe because it does not check the bounds of the array.
419{-# INLINE_NORMAL getIndexUnsafe #-}
419{-# INLINE_NORMAL getIndexUnsafe #-}
420−getIndexUnsafe :: MonadIO m => Array a -> Int -> m a
420+getIndexUnsafe :: MonadIO m => Int -> Array a -> m a
421−getIndexUnsafe Array {..} n =
421+getIndexUnsafe n Array {..} =
@@ -428,10 +428,10 @@ getIndexUnsafe Array {..} n =
428-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
428-- | /O(1)/ Lookup the element at the given index. Index starts from 0.
430{-# INLINE getIndex #-}
430{-# INLINE getIndex #-}
431−getIndex :: MonadIO m => Array a -> Int -> m a
431+getIndex :: MonadIO m => Int -> Array a -> m a
432−getIndex arr@Array {..} i =
432+getIndex i arr@Array {..} =
433 if i >= 0 && i < arrLen
433 if i >= 0 && i < arrLen
434− then getIndexUnsafe arr i
434+ then getIndexUnsafe i arr
435 else invalidIndex "getIndex" i
435 else invalidIndex "getIndex" i
437-------------------------------------------------------------------------------
437-------------------------------------------------------------------------------
@@ -484,7 +484,7 @@ getSlice index len arr@Array{..} =
484-- /Pre-release/
484-- /Pre-release/
485{-# INLINE toList #-}
485{-# INLINE toList #-}
486toList :: MonadIO m => Array a -> m [a]
486toList :: MonadIO m => Array a -> m [a]
487−toList arr@Array{..} = mapM (getIndexUnsafe arr) [0 .. (arrLen - 1)]
487+toList arr@Array{..} = mapM (`getIndexUnsafe` arr) [0 .. (arrLen - 1)]
489-- | Use the 'read' unfold instead.
489-- | Use the 'read' unfold instead.
@@ -494,7 +494,7 @@ toList arr@Array{..} = mapM (getIndexUnsafe arr) [0 .. (arrLen - 1)]
494{-# INLINE_NORMAL toStreamD #-}
494{-# INLINE_NORMAL toStreamD #-}
495toStreamD :: MonadIO m => Array a -> D.Stream m a
495toStreamD :: MonadIO m => Array a -> D.Stream m a
496toStreamD arr@Array{..} =
496toStreamD arr@Array{..} =
497− D.mapM (getIndexUnsafe arr) $ D.enumerateFromToIntegral 0 (arrLen - 1)
497+ D.mapM (`getIndexUnsafe` arr) $ D.enumerateFromToIntegral 0 (arrLen - 1)
499{-# INLINE toStreamK #-}
499{-# INLINE toStreamK #-}
500toStreamK :: MonadIO m => Array a -> K.Stream m a
500toStreamK :: MonadIO m => Array a -> K.Stream m a
@@ -505,7 +505,7 @@ toStreamK arr@Array{..} = K.unfoldrM step 0
506 | i == arrLen = return Nothing
506 | i == arrLen = return Nothing
507 | otherwise = do
507 | otherwise = do
508− x <- getIndexUnsafe arr i
508+ x <- getIndexUnsafe i arr
509 return $ Just (x, i + 1)
509 return $ Just (x, i + 1)
@@ -563,7 +563,7 @@ producerWith liftio = Producer step inject extract
563 step (arr, i)
563 step (arr, i)
564 | assert (arrLen arr >= 0) (i == arrLen arr) = return D.Stop
564 | assert (arrLen arr >= 0) (i == arrLen arr) = return D.Stop
565 step (arr, i) = do
565 step (arr, i) = do
566− x <- liftio $ getIndexUnsafe arr i
566+ x <- liftio $ getIndexUnsafe i arr
567 return $ D.Yield x (arr, i + 1)
567 return $ D.Yield x (arr, i + 1)
569-- | Resumable unfold of an array.
569-- | Resumable unfold of an array.