Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions vector/src/Data/Vector.hs
Original file line number Diff line number Diff line change
Expand Up @@ -187,6 +187,7 @@ import Data.Vector.Mutable.Unsafe ( MVector )
import Data.Vector.Unsafe ( Vector(..) )
import qualified Data.Vector.Unsafe as U
import qualified Data.Vector.Generic as G
import GHC.Stack (HasCallStack)

import Control.Monad.ST ( ST )
import Control.Monad.Primitive
Expand Down Expand Up @@ -242,7 +243,7 @@ null = G.null
-- --------

-- | O(1) Indexing.
(!) :: Vector a -> Int -> a
(!) :: HasCallStack => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)

Expand Down Expand Up @@ -297,7 +298,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
indexM :: Monad m => Vector a -> Int -> m a
indexM :: (HasCallStack, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM

Expand Down Expand Up @@ -336,10 +337,11 @@ unsafeLastM = G.unsafeLastM

-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
slice :: Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
-> Vector a
slice :: HasCallStack
=> Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
-> Vector a
{-# INLINE slice #-}
slice = G.slice

Expand Down Expand Up @@ -805,7 +807,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
backpermute :: Vector a -> Vector Int -> Vector a
backpermute :: HasCallStack => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute

Expand Down Expand Up @@ -2113,7 +2115,7 @@ unsafeCopy = G.unsafeCopy

-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
copy :: PrimMonad m => MVector (PrimState m) a -> Vector a -> m ()
copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy

Expand Down
21 changes: 11 additions & 10 deletions vector/src/Data/Vector/Mutable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ import Data.Vector.Mutable.Unsafe (MVector(..))
import Data.Vector.Pattern
import Data.Primitive.Array
import Control.Monad.Primitive
import GHC.Stack (HasCallStack)

import Prelude( Ord, Bool, Ordering(..), Int, Maybe, (<$>) )

Expand Down Expand Up @@ -209,7 +210,7 @@ overlaps = G.overlaps
-- --------------

-- | Create a mutable vector of the given length.
new :: PrimMonad m => Int -> m (MVector (PrimState m) a)
new :: (HasCallStack, PrimMonad m) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new

Expand Down Expand Up @@ -293,7 +294,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.5
grow :: PrimMonad m
grow :: (HasCallStack, PrimMonad m)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
Expand Down Expand Up @@ -328,7 +329,7 @@ clear = G.clear
-- >>> v <- MV.generate 10 (\x -> x*x)
-- >>> MV.read v 3
-- 9
read :: PrimMonad m => MVector (PrimState m) a -> Int -> m a
read :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read

Expand All @@ -350,29 +351,29 @@ readMaybe :: (PrimMonad m) => MVector (PrimState m) a -> Int -> m (Maybe a)
readMaybe = G.readMaybe

-- | Replace the element at the given position.
write :: PrimMonad m => MVector (PrimState m) a -> Int -> a -> m ()
write :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write

-- | Modify the element at the given position.
modify :: PrimMonad m => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
modify :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify

-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
modifyM :: (PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
modifyM :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM

-- | Swap the elements at the given positions.
swap :: PrimMonad m => MVector (PrimState m) a -> Int -> Int -> m ()
swap :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap

-- | Replace the element at the given position and return the old element.
exchange :: (PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
exchange :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange

Expand Down Expand Up @@ -420,7 +421,7 @@ set = G.set

-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
copy :: PrimMonad m => MVector (PrimState m) a -- ^ target
copy :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE copy #-}
Expand All @@ -441,7 +442,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
move :: PrimMonad m => MVector (PrimState m) a -- ^ target
move :: (HasCallStack, PrimMonad m) => MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
{-# INLINE move #-}
Expand Down
10 changes: 5 additions & 5 deletions vector/src/Data/Vector/Primitive.hs
Original file line number Diff line number Diff line change
Expand Up @@ -199,7 +199,7 @@ null = G.null
-- --------

-- | O(1) Indexing.
(!) :: Prim a => Vector a -> Int -> a
(!) :: (HasCallStack, Prim a) => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)

Expand Down Expand Up @@ -254,7 +254,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
indexM :: (Prim a, Monad m) => Vector a -> Int -> m a
indexM :: (HasCallStack, Prim a, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM

Expand Down Expand Up @@ -293,7 +293,7 @@ unsafeLastM = G.unsafeLastM

-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
slice :: Prim a
slice :: (HasCallStack, Prim a)
=> Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
Expand Down Expand Up @@ -716,7 +716,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
backpermute :: Prim a => Vector a -> Vector Int -> Vector a
backpermute :: (HasCallStack, Prim a) => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute

Expand Down Expand Up @@ -1905,7 +1905,7 @@ unsafeCopy = G.unsafeCopy

-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
copy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
copy :: (HasCallStack, Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy

Expand Down
20 changes: 10 additions & 10 deletions vector/src/Data/Vector/Primitive/Mutable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -192,7 +192,7 @@ overlaps = G.overlaps
-- --------------

-- | Create a mutable vector of the given length.
new :: (PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
new :: (HasCallStack, PrimMonad m, Prim a) => Int -> m (MVector (PrimState m) a)
{-# INLINE new #-}
new = G.new

Expand Down Expand Up @@ -279,7 +279,7 @@ clone = G.clone
-- [10,20,30]
--
-- @since 0.5
grow :: (PrimMonad m, Prim a)
grow :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -> Int -> m (MVector (PrimState m) a)
{-# INLINE grow #-}
grow = G.grow
Expand Down Expand Up @@ -314,7 +314,7 @@ clear = G.clear
-- >>> v <- MVP.generate 10 (\x -> x*x)
-- >>> MVP.read v 3
-- 9
read :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
read :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m a
{-# INLINE read #-}
read = G.read

Expand All @@ -336,29 +336,29 @@ readMaybe :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> m (Maybe
readMaybe = G.readMaybe

-- | Replace the element at the given position.
write :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
write :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m ()
{-# INLINE write #-}
write = G.write

-- | Modify the element at the given position.
modify :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
modify :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> a) -> Int -> m ()
{-# INLINE modify #-}
modify = G.modify

-- | Modify the element at the given position using a monadic function.
--
-- @since 0.12.3.0
modifyM :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
modifyM :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> (a -> m a) -> Int -> m ()
{-# INLINE modifyM #-}
modifyM = G.modifyM

-- | Swap the elements at the given positions.
swap :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
swap :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> Int -> m ()
{-# INLINE swap #-}
swap = G.swap

-- | Replace the element at the given position and return the old element.
exchange :: (PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
exchange :: (HasCallStack, PrimMonad m, Prim a) => MVector (PrimState m) a -> Int -> a -> m a
{-# INLINE exchange #-}
exchange = G.exchange

Expand Down Expand Up @@ -406,7 +406,7 @@ set = G.set

-- | Copy a vector. The two vectors must have the same length and may not
-- overlap.
copy :: (PrimMonad m, Prim a)
copy :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
Expand All @@ -429,7 +429,7 @@ unsafeCopy = G.unsafeCopy
-- Otherwise, the copying is performed as if the source vector were
-- copied to a temporary vector and then the temporary vector was copied
-- to the target vector.
move :: (PrimMonad m, Prim a)
move :: (HasCallStack, PrimMonad m, Prim a)
=> MVector (PrimState m) a -- ^ target
-> MVector (PrimState m) a -- ^ source
-> m ()
Expand Down
11 changes: 6 additions & 5 deletions vector/src/Data/Vector/Storable.hs
Original file line number Diff line number Diff line change
Expand Up @@ -173,6 +173,7 @@ import qualified Data.Vector.Generic as G
import Data.Vector.Storable.Mutable ( MVector, pattern MVector )
import Data.Vector.Storable.Unsafe (Vector(..))
import qualified Data.Vector.Storable.Unsafe as U
import GHC.Stack (HasCallStack)

import Control.Monad.ST ( ST )
import Control.Monad.Primitive
Expand Down Expand Up @@ -203,7 +204,7 @@ null = G.null
-- --------

-- | O(1) Indexing.
(!) :: Storable a => Vector a -> Int -> a
(!) :: (HasCallStack, Storable a) => Vector a -> Int -> a
{-# INLINE (!) #-}
(!) = (G.!)

Expand Down Expand Up @@ -258,7 +259,7 @@ unsafeLast = G.unsafeLast
--
-- Here, no references to @v@ are retained because indexing (but /not/ the
-- element) is evaluated eagerly.
indexM :: (Storable a, Monad m) => Vector a -> Int -> m a
indexM :: (HasCallStack, Storable a, Monad m) => Vector a -> Int -> m a
{-# INLINE indexM #-}
indexM = G.indexM

Expand Down Expand Up @@ -297,7 +298,7 @@ unsafeLastM = G.unsafeLastM

-- | /O(1)/ Yield a slice of the vector without copying it. The vector must
-- contain at least @i+n@ elements.
slice :: Storable a
slice :: (HasCallStack, Storable a)
=> Int -- ^ @i@ starting index
-> Int -- ^ @n@ length
-> Vector a
Expand Down Expand Up @@ -720,7 +721,7 @@ reverse = G.reverse
-- often much more efficient.
--
-- > backpermute <a,b,c,d> <0,3,2,3,1,0> = <a,d,c,d,b,a>
backpermute :: Storable a => Vector a -> Vector Int -> Vector a
backpermute :: (HasCallStack, Storable a) => Vector a -> Vector Int -> Vector a
{-# INLINE backpermute #-}
backpermute = G.backpermute

Expand Down Expand Up @@ -1945,7 +1946,7 @@ unsafeCopy = G.unsafeCopy

-- | /O(n)/ Copy an immutable vector into a mutable one. The two vectors must
-- have the same length.
copy :: (Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
copy :: (HasCallStack, Storable a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m ()
{-# INLINE copy #-}
copy = G.copy

Expand Down
Loading
Loading