packages feed

vector 0.13.0.0 → 0.13.1.0

raw patch · 22 files changed

+302/−238 lines, 22 filesdep ~QuickCheckdep ~basedep ~doctestnew-uploader

Dependency ranges changed: QuickCheck, base, doctest, primitive

Files

changelog.md view
@@ -1,3 +1,20 @@+# Changes in version 0.13.1.0++ * Specialized variants of `findIndexR` are reexported for all vector+   types. [#469](https://github.com/haskell/vector/pull/469)+ * `UnboxViaPrim` could be used for deriving `Unbox` instances (`V_UnboxViaPrim`+   constructor is exported) [#450](https://github.com/haskell/vector/pull/450)+ * Fields of `Data.Vector.Fusion.Bundle.Size` are now strict+   [#456](https://github.com/haskell/vector/pull/456)+ * Compatibility with future GHC 9.10 release+   [#462](https://github.com/haskell/vector/pull/462)+ * Test suite no longer fails when built with QuickCheck-2.14+   [#461](https://github.com/haskell/vector/pull/461)+ * Doctests now work with current versions of GHC+   [#465](https://github.com/haskell/vector/pull/466)+ * Various documentation improvements++ # Changes in version 0.13.0.0   * `mkType` from `Data.Vector.Generic` is deprecated in favor of
src/Data/Vector.hs view
@@ -125,7 +125,7 @@   partition, unstablePartition, partitionWith, span, break, groupBy, group,    -- ** Searching-  elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,+  elem, notElem, find, findIndex, findIndexR, findIndices, elemIndex, elemIndices,    -- * Folding   foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',@@ -187,6 +187,9 @@                        )  import Control.Monad ( MonadPlus(..), liftM, ap )+#if !MIN_VERSION_base(4,13,0)+import Control.Monad (fail)+#endif import Control.Monad.ST ( ST, runST ) import Control.Monad.Primitive import qualified Control.Monad.Fail as Fail@@ -194,19 +197,10 @@ import Control.Monad.Zip import Data.Function ( fix ) -import Prelude hiding ( length, null,-                        replicate, (++), concat,-                        head, last,-                        init, tail, take, drop, splitAt, reverse,-                        map, concatMap,-                        zipWith, zipWith3, zip, zip3, unzip, unzip3,-                        filter, takeWhile, dropWhile, span, break,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1, foldMap,-                        all, any, and, or, sum, product, minimum, maximum,-                        scanl, scanl1, scanr, scanr1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_, sequence, sequence_ )+import Prelude+  ( Eq, Ord, Num, Enum, Monoid, Functor, Monad, Show, Bool, Ordering(..), Int, Maybe, Either+  , compare, mempty, mappend, mconcat, return, showsPrec, fmap, otherwise, id, flip, const+  , (>>=), (+), (-), (<), (<=), (>), (>=), (==), (/=), (&&), (.), ($) )  import Data.Functor.Classes (Eq1 (..), Ord1 (..), Read1 (..), Show1 (..)) import Data.Typeable  ( Typeable )@@ -1065,13 +1059,16 @@ -- Safe destructive updates -- ------------------------ --- | Apply a destructive operation to a vector. The operation will be+-- | Apply a destructive operation to a vector. The operation may be -- performed in place if it is safe to do so and will modify a copy of the--- vector otherwise.+-- vector otherwise (see 'Data.Vector.Generic.New.New' for details). ----- @--- modify (\\v -> write v 0 \'x\') ('replicate' 3 \'a\') = \<\'x\',\'a\',\'a\'\>--- @+-- ==== __Examples__+--+-- >>> import qualified Data.Vector as V+-- >>> import qualified Data.Vector.Mutable as MV+-- >>> V.modify (\v -> MV.write v 0 'x') $ V.replicate 4 'a'+-- "xaaa" modify :: (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p@@ -1480,6 +1477,14 @@ {-# INLINE findIndex #-} findIndex = G.findIndex +-- | /O(n)/ Yield 'Just' the index of the /last/ element matching the predicate+-- or 'Nothing' if no such element exists.+--+-- Does not fuse.+findIndexR :: (a -> Bool) -> Vector a -> Maybe Int+{-# INLINE findIndexR #-}+findIndexR = G.findIndexR+ -- | /O(n)/ Yield the indices of elements satisfying the predicate in ascending -- order. findIndices :: (a -> Bool) -> Vector a -> Vector Int@@ -2247,3 +2252,4 @@  -- $setup -- >>> :set -Wno-type-defaults+-- >>> import Prelude (Char, String, Bool(True, False), min, max, fst, even, undefined)
src/Data/Vector/Fusion/Bundle.hs view
@@ -89,19 +89,10 @@ import qualified Data.Vector.Fusion.Bundle.Monadic as M import qualified Data.Vector.Fusion.Stream.Monadic as S -import Prelude hiding ( length, null,-                        replicate, (++),-                        head, last, (!!),-                        init, tail, take, drop,-                        map, concatMap,-                        zipWith, zipWith3, zip, zip3,-                        filter, takeWhile, dropWhile,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1,-                        and, or,-                        scanl, scanl1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_ )+import Prelude+  ( Eq, Ord, Num, Enum, Monad, Bool, Ordering, Int, Maybe+  , compare, return, seq+  , (==), (.) )  import Data.Functor.Classes (Eq1 (..), Ord1 (..)) import GHC.Base ( build )
src/Data/Vector/Fusion/Bundle/Monadic.hs view
@@ -100,18 +100,10 @@ import Data.Char      ( ord ) import GHC.Base       ( unsafeChr ) import Control.Monad  ( liftM )-import Prelude hiding ( length, null,-                        replicate, (++),-                        head, last, (!!),-                        init, tail, take, drop,-                        map, mapM, mapM_, concatMap,-                        zipWith, zipWith3, zip, zip3,-                        filter, takeWhile, dropWhile,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1,-                        and, or,-                        scanl, scanl1,-                        enumFromTo, enumFromThenTo )+import Prelude+  ( Eq, Ord, Num, Enum, Functor, Monad, Bool(..), Ordering, Char, Int, Word, Integer, Float, Double, Maybe(..), Either(..), Integral, RealFrac+  , return, fmap, otherwise, id, const, seq, max, maxBound, fromIntegral, truncate+  , (+), (-), (<), (<=), (>), (>=), (==), (/=), (&&), (.), ($), (<$), (/) )  import Data.Int  ( Int8, Int16, Int32 ) import Data.Word ( Word8, Word16, Word32, Word64 )
src/Data/Vector/Fusion/Bundle/Size.hs view
@@ -20,9 +20,9 @@ import Data.Vector.Fusion.Util ( delay_inline )  -- | Size hint-data Size = Exact Int          -- ^ Exact size-          | Max   Int          -- ^ Upper bound on the size-          | Unknown            -- ^ Unknown size+data Size = Exact {-# UNPACK #-} !Int -- ^ Exact size+          | Max   {-# UNPACK #-} !Int -- ^ Upper bound on the size+          | Unknown                   -- ^ Unknown size         deriving( Eq, Show )  instance Num Size where
src/Data/Vector/Generic.hs view
@@ -196,20 +196,10 @@  import Control.Monad.ST ( ST, runST ) import Control.Monad.Primitive-import Prelude hiding ( length, null,-                        replicate, (++), concat,-                        head, last,-                        init, tail, take, drop, splitAt, reverse,-                        map, concat, concatMap,-                        zipWith, zipWith3, zip, zip3, unzip, unzip3,-                        filter, takeWhile, dropWhile, span, break,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1, foldMap,-                        all, any, and, or, sum, product, maximum, minimum,-                        scanl, scanl1, scanr, scanr1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_, sequence, sequence_,-                        showsPrec )+import Prelude+  ( Eq, Ord, Num, Enum, Monoid, Monad, Read, Show, Bool, Ordering(..), Int, Maybe(..), Either, IO, ShowS, ReadS, String+  , compare, mempty, mappend, return, fmap, otherwise, id, flip, seq, error, undefined, uncurry, shows, fst, snd, min, max, not+  , (>>=), (+), (-), (*), (<), (==), (.), ($), (=<<), (>>), (<$>) )  import qualified Text.Read as Read import qualified Data.List.NonEmpty as NonEmpty@@ -1025,13 +1015,16 @@ -- Safe destructive updates -- ------------------------ --- | Apply a destructive operation to a vector. The operation will be+-- | Apply a destructive operation to a vector. The operation may be -- performed in place if it is safe to do so and will modify a copy of the--- vector otherwise.+-- vector otherwise (see 'Data.Vector.Generic.New.New' for details). ----- @--- modify (\\v -> 'M.write' v 0 \'x\') ('replicate' 3 \'a\') = \<\'x\',\'a\',\'a\'\>--- @+-- ==== __Examples__+--+-- >>> import qualified Data.Vector as V+-- >>> import qualified Data.Vector.Mutable as MV+-- >>> V.modify (\v -> MV.write v 0 'x') $ V.replicate 4 'a'+-- "xaaa" modify :: Vector v a => (forall s. Mutable v s a -> ST s ()) -> v a -> v a {-# INLINE modify #-} modify p = new . New.modify p . clone@@ -1627,6 +1620,8 @@ -- | /O(n)/ Yield 'Just' the index of the /last/ element matching the predicate -- or 'Nothing' if no such element exists. --+-- Does not fuse.+-- -- @since 0.12.2.0 findIndexR :: Vector v a => (a -> Bool) -> v a -> Maybe Int {-# INLINE findIndexR #-}@@ -2664,3 +2659,4 @@ -- $setup -- >>> :set -XFlexibleContexts -- >>> :set -Wno-type-defaults+-- >>> import Prelude (Bool(True, False), even)
src/Data/Vector/Generic/Mutable.hs view
@@ -90,8 +90,10 @@  import Control.Monad.Primitive ( PrimMonad(..), RealWorld, stToPrim ) -import Prelude hiding ( length, null, replicate, reverse, map, read,-                        take, drop, splitAt, init, tail, mapM_, foldr, foldl )+import Prelude+  ( Ord, Monad, Bool(..), Int, Maybe(..), Either(..)+  , return, otherwise, flip, const, seq, min, max, not, pure+  , (>>=), (+), (-), (<), (<=), (>=), (==), (/=), (.), ($), (=<<), (>>), (<$>) )  #include "vector.h" @@ -505,14 +507,7 @@ -- @since 0.12.3.0 generateM :: (PrimMonad m, MVector v a) => Int -> (Int -> m a) -> m (v (PrimState m) a) {-# INLINE generateM #-}-generateM n f-  | n <= 0    = new 0-  | otherwise = do-      vec <- new n-      let loop i | i >= n    = return vec-                 | otherwise = do unsafeWrite vec i =<< f i-                                  loop (i + 1)-      loop 0+generateM n f = munstream (MBundle.generateM n f)  -- | Create a copy of a mutable vector. clone :: (PrimMonad m, MVector v a) => v (PrimState m) a -> m (v (PrimState m) a)@@ -1248,3 +1243,6 @@                       l' = if kval' < cur then i else l                   loop kval' k' l' cur (i+1)           dim = length v++-- $setup+-- >>> import Prelude ((*))
src/Data/Vector/Generic/New.hs view
@@ -18,10 +18,13 @@ --  module Data.Vector.Generic.New (+  -- * Array recycling primitives   New(..), create, run, runPrim, apply, modify, modifyWithBundle,   unstream, transform, unstreamR, transformR,   slice, init, tail, take, drop,   unsafeSlice, unsafeInit, unsafeTail+  -- * References+  -- $references ) where  import qualified Data.Vector.Generic.Mutable as MVector@@ -36,12 +39,22 @@ import Control.Monad.Primitive import Control.Monad.ST ( ST ) import Control.Monad  ( liftM )-import Prelude hiding ( init, tail, take, drop, reverse, map, filter )+import Prelude+  ( Monad, Int+  , return, seq+  , (.), (=<<) )  -- Data.Vector.Internal.Check is unused #define NOT_VECTOR_MODULE #include "vector.h" +-- | This data type is a wrapper around a monadic action which produces+-- a mutable vector. It's used by a number of rewrite rules in order to+-- facilitate the reuse of buffers allocated for vectors. See "Recycle+-- your arrays!" for a detailed explanation.+--+-- Note that this data type must be declared as @data@ and not @newtype@+-- since it's used for rewrite rules and rules won't fire with @newtype@. data New v a = New (forall s. ST s (Mutable v s a))  create :: (forall s. ST s (Mutable v s a)) -> New v a@@ -180,3 +193,9 @@   unsafeTail (unstream s) = unstream (Bundle.tail s)   #-}  +-- $references+--+-- * Leshchinskiy, Roman. "Recycle your arrays!". Practical Aspects of+--   Declarative Languages: 11th International Symposium, PADL 2009,+--   Savannah, GA, USA, January 19-20, 2009. Proceedings 11. Springer+--   Berlin Heidelberg, 2009.
src/Data/Vector/Internal/Check.hs view
@@ -27,7 +27,10 @@ ) where  import GHC.Exts (Int(..), Int#)-import Prelude hiding( error, (&&), (||), not )+import Prelude+  ( Eq, Bool(..), Word, String+  , otherwise, fromIntegral, show, unlines+  , (-), (<), (<=), (>=), ($), (++) ) import qualified Prelude as P import GHC.Stack (HasCallStack) 
src/Data/Vector/Mutable.hs view
@@ -76,8 +76,10 @@ import           Data.Primitive.Array import           Control.Monad.Primitive -import Prelude hiding ( length, null, replicate, reverse, read,-                        take, drop, splitAt, init, tail, foldr, foldl, mapM_ )+import Prelude+  ( Ord, Monad, Bool, Ordering(..), Int, Maybe+  , compare, return, otherwise, error+  , (>>=), (+), (-), (*), (<), (>), (>=), (&&), (||), ($), (>>) )  import Data.Typeable ( Typeable ) @@ -742,3 +744,6 @@ toMutableArray :: PrimMonad m => MVector (PrimState m) a -> m (MutableArray (PrimState m) a) {-# INLINE toMutableArray #-} toMutableArray (MVector offset size marr) = cloneMutableArray marr offset size++-- $setup+-- >>> import Prelude (Integer)
src/Data/Vector/Primitive.hs view
@@ -110,7 +110,7 @@   partition, unstablePartition, partitionWith, span, break, groupBy, group,    -- ** Searching-  elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,+  elem, notElem, find, findIndex, findIndexR, findIndices, elemIndex, elemIndices,    -- * Folding   foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',@@ -175,19 +175,10 @@ import Control.Monad.ST ( ST ) import Control.Monad.Primitive -import Prelude hiding ( length, null,-                        replicate, (++), concat,-                        head, last,-                        init, tail, take, drop, splitAt, reverse,-                        map, concatMap,-                        zipWith, zipWith3, zip, zip3, unzip, unzip3,-                        filter, takeWhile, dropWhile, span, break,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1, foldMap,-                        all, any, sum, product, minimum, maximum,-                        scanl, scanl1, scanr, scanr1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_ )+import Prelude+  ( Eq, Ord, Num, Enum, Monoid, Traversable, Monad, Read, Show, Bool, Ordering(..), Int, Maybe, Either+  , compare, mempty, mappend, mconcat, showsPrec, return, otherwise, seq, error, undefined+  , (+), (*), (<), (<=), (>), (>=), (==), (/=), ($!) )  import Data.Typeable  ( Typeable ) import Data.Data      ( Data(..) )@@ -862,13 +853,16 @@ -- Safe destructive updates -- ------------------------ --- | Apply a destructive operation to a vector. The operation will be+-- | Apply a destructive operation to a vector. The operation may be -- performed in place if it is safe to do so and will modify a copy of the--- vector otherwise.+-- vector otherwise (see 'Data.Vector.Generic.New.New' for details). ----- @--- modify (\\v -> write v 0 \'x\') ('replicate' 3 \'a\') = \<\'x\',\'a\',\'a\'\>--- @+-- ==== __Examples__+--+-- >>> import qualified Data.Vector.Primitive as VP+-- >>> import qualified Data.Vector.Primitive.Mutable as MVP+-- >>> VP.modify (\v -> MVP.write v 0 'x') $ VP.replicate 4 'a'+-- "xaaa" modify :: Prim a => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p@@ -1239,6 +1233,14 @@ {-# INLINE findIndex #-} findIndex = G.findIndex +-- | /O(n)/ Yield 'Just' the index of the /last/ element matching the predicate+-- or 'Nothing' if no such element exists.+--+-- Does not fuse.+findIndexR :: Prim a => (a -> Bool) -> Vector a -> Maybe Int+{-# INLINE findIndexR #-}+findIndexR = G.findIndexR+ -- | /O(n)/ Yield the indices of elements satisfying the predicate in ascending -- order. findIndices :: Prim a => (a -> Bool) -> Vector a -> Vector Int@@ -1890,3 +1892,6 @@ copy :: (Prim a, PrimMonad m) => MVector (PrimState m) a -> Vector a -> m () {-# INLINE copy #-} copy = G.copy++-- $setup+-- >>> import Prelude (($), min, even, max, succ)
src/Data/Vector/Primitive/Mutable.hs view
@@ -82,8 +82,10 @@ #endif                        ) -import Prelude hiding ( length, null, replicate, reverse, map, read,-                        take, drop, splitAt, init, tail, foldr, foldl, mapM_ )+import Prelude+  ( Ord, Bool, Int, Maybe+  , otherwise, error, undefined, div, show, maxBound+  , (+), (*), (<), (>), (>=), (==), (&&), (||), ($), (++) )  import Data.Typeable ( Typeable ) import Data.Coerce
src/Data/Vector/Storable.hs view
@@ -107,7 +107,7 @@   partition, unstablePartition, partitionWith, span, break, groupBy, group,    -- ** Searching-  elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,+  elem, notElem, find, findIndex, findIndexR, findIndices, elemIndex, elemIndices,    -- * Folding   foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',@@ -183,19 +183,10 @@ import Control.Monad.ST ( ST ) import Control.Monad.Primitive -import Prelude hiding ( length, null,-                        replicate, (++), concat,-                        head, last,-                        init, tail, take, drop, splitAt, reverse,-                        map, concatMap,-                        zipWith, zipWith3, zip, zip3, unzip, unzip3,-                        filter, takeWhile, dropWhile, span, break,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1, foldMap,-                        all, any, and, or, sum, product, minimum, maximum,-                        scanl, scanl1, scanr, scanr1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_ )+import Prelude+  ( Eq, Ord, Num, Enum, Monoid, Traversable, Monad, Read, Show, Bool, Ordering(..), Int, Maybe, Either, IO+  , compare, mempty, mappend, mconcat, showsPrec, return, seq, undefined, div+  , (*), (<), (<=), (>), (>=), (==), (/=), (&&), (.), ($) )  import Data.Typeable  ( Typeable ) import Data.Data      ( Data(..) )@@ -873,13 +864,16 @@ -- Safe destructive updates -- ------------------------ --- | Apply a destructive operation to a vector. The operation will be+-- | Apply a destructive operation to a vector. The operation may be -- performed in place if it is safe to do so and will modify a copy of the--- vector otherwise.+-- vector otherwise (see 'Data.Vector.Generic.New.New' for details). ----- @--- modify (\\v -> write v 0 \'x\') ('replicate' 3 \'a\') = \<\'x\',\'a\',\'a\'\>--- @+-- ==== __Examples__+--+-- >>> import qualified Data.Vector.Storable as VS+-- >>> import qualified Data.Vector.Storable.Mutable as MVS+-- >>> VS.modify (\v -> MVS.write v 0 'x') $ VS.replicate 4 'a'+-- "xaaa" modify :: Storable a => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p@@ -1038,7 +1032,8 @@ -- | Checks whether two values are the same vector: they have same length -- and share the same buffer. ----- >>> let xs = fromList [0/0::Double] in isSameVector xs xs+-- >>> import qualified Data.Vector.Storable as VS+-- >>> let xs = VS.fromList [0/0::Double] in VS.isSameVector xs xs -- True isSameVector :: (Storable a) => Vector a -> Vector a -> Bool {-# INLINE isSameVector #-}@@ -1260,6 +1255,14 @@ {-# INLINE findIndex #-} findIndex = G.findIndex +-- | /O(n)/ Yield 'Just' the index of the /last/ element matching the predicate+-- or 'Nothing' if no such element exists.+--+-- Does not fuse.+findIndexR :: Storable a => (a -> Bool) -> Vector a -> Maybe Int+{-# INLINE findIndexR #-}+findIndexR = G.findIndexR+ -- | /O(n)/ Yield the indices of elements satisfying the predicate in ascending -- order. findIndices :: Storable a => (a -> Bool) -> Vector a -> Vector Int@@ -1993,3 +1996,6 @@ unsafeWith :: Storable a => Vector a -> (Ptr a -> IO b) -> IO b {-# INLINE unsafeWith #-} unsafeWith (Vector _ fp) = withForeignPtr fp++-- $setup+-- >>> import Prelude (Bool(..), Double, ($), (+), (/), succ, even, min, max)
src/Data/Vector/Storable/Mutable.hs view
@@ -100,8 +100,10 @@ import GHC.Word (Word8, Word16, Word32, Word64) import GHC.Ptr (Ptr(..)) -import Prelude hiding ( length, null, replicate, reverse, map, read,-                        take, drop, splitAt, init, tail, foldr, foldl, mapM_ )+import Prelude+  ( Ord, Bool, Maybe, IO+  , return, otherwise, error, undefined, max, div, quot, maxBound, show+  , (-), (*), (<), (>), (>=), (==), (&&), (||), (.), ($), (++) )  import Data.Typeable ( Typeable ) 
src/Data/Vector/Unboxed.hs view
@@ -46,21 +46,21 @@ -- -- >>> :set -XTypeFamilies -XStandaloneDeriving -XMultiParamTypeClasses -XGeneralizedNewtypeDeriving -- >>>--- >>> import qualified Data.Vector.Unboxed         as U--- >>> import qualified Data.Vector.Generic         as G--- >>> import qualified Data.Vector.Generic.Mutable as M+-- >>> import qualified Data.Vector.Generic         as VG+-- >>> import qualified Data.Vector.Generic.Mutable as VGM+-- >>> import qualified Data.Vector.Unboxed         as VU -- >>> -- >>> newtype Foo = Foo Int -- >>>--- >>> newtype instance U.MVector s Foo = MV_Int (U.MVector s Int)--- >>> newtype instance U.Vector    Foo = V_Int  (U.Vector    Int)--- >>> deriving instance M.MVector MVector Foo--- >>> deriving instance G.Vector  Vector  Foo--- >>> instance Unbox Foo+-- >>> newtype instance VU.MVector s Foo = MV_Int (VU.MVector s Int)+-- >>> newtype instance VU.Vector    Foo = V_Int  (VU.Vector    Int)+-- >>> deriving instance VGM.MVector VU.MVector Foo+-- >>> deriving instance VG.Vector   VU.Vector  Foo+-- >>> instance VU.Unbox Foo  module Data.Vector.Unboxed (   -- * Unboxed vectors-  Vector(V_UnboxAs), MVector(..), Unbox,+  Vector(V_UnboxAs, V_UnboxViaPrim), MVector(..), Unbox,    -- * Accessors @@ -152,7 +152,7 @@   partition, unstablePartition, partitionWith, span, break, groupBy, group,    -- ** Searching-  elem, notElem, find, findIndex, findIndices, elemIndex, elemIndices,+  elem, notElem, find, findIndex, findIndexR, findIndices, elemIndex, elemIndices,    -- * Folding   foldl, foldl1, foldl', foldl1', foldr, foldr1, foldr', foldr1',@@ -209,19 +209,10 @@ import Control.Monad.ST ( ST ) import Control.Monad.Primitive -import Prelude hiding ( length, null,-                        replicate, (++), concat,-                        head, last,-                        init, tail, take, drop, splitAt, reverse,-                        map, concatMap,-                        zipWith, zipWith3, zip, zip3, unzip, unzip3,-                        filter, takeWhile, dropWhile, span, break,-                        elem, notElem,-                        foldl, foldl1, foldr, foldr1, foldMap,-                        all, any, and, or, sum, product, minimum, maximum,-                        scanl, scanl1, scanr, scanr1,-                        enumFromTo, enumFromThenTo,-                        mapM, mapM_ )+import Prelude+  ( Eq, Ord, Num, Enum, Monoid, Traversable, Monad, Read, Show, Bool, Ordering(..), Int, Maybe, Either+  , compare, mempty, mappend, mconcat, showsPrec+  , (<), (<=), (>), (>=), (==), (/=) )  import Text.Read      ( Read(..), readListPrecDefault ) import Data.Semigroup ( Semigroup(..) )@@ -880,13 +871,16 @@ -- Safe destructive updates -- ------------------------ --- | Apply a destructive operation to a vector. The operation will be+-- | Apply a destructive operation to a vector. The operation may be -- performed in place if it is safe to do so and will modify a copy of the--- vector otherwise.+-- vector otherwise (see 'Data.Vector.Generic.New.New' for details). ----- @--- modify (\\v -> write v 0 \'x\') ('replicate' 3 \'a\') = \<\'x\',\'a\',\'a\'\>--- @+-- ==== __Examples__+--+-- >>> import qualified Data.Vector.Unboxed as VU+-- >>> import qualified Data.Vector.Unboxed.Mutable as MVU+-- >>> VU.modify (\v -> MVU.write v 0 'x') $ VU.replicate 4 'a'+-- "xaaa" modify :: Unbox a => (forall s. MVector s a -> ST s ()) -> Vector a -> Vector a {-# INLINE modify #-} modify p = G.modify p@@ -1250,6 +1244,14 @@ {-# INLINE findIndex #-} findIndex = G.findIndex +-- | /O(n)/ Yield 'Just' the index of the /last/ element matching the predicate+-- or 'Nothing' if no such element exists.+--+-- Does not fuse.+findIndexR :: Unbox a => (a -> Bool) -> Vector a -> Maybe Int+{-# INLINE findIndexR #-}+findIndexR = G.findIndexR+ -- | /O(n)/ Yield the indices of elements satisfying the predicate in ascending -- order. findIndices :: Unbox a => (a -> Bool) -> Vector a -> Vector Int@@ -1970,3 +1972,6 @@  #define DEFINE_IMMUTABLE #include "unbox-tuple-instances"++-- $setup+-- >>> import Prelude (Bool(True, False), ($), (+), min, max, even, fst, pred, succ, undefined)
src/Data/Vector/Unboxed/Base.hs view
@@ -184,36 +184,36 @@ -- >>> -- Needed to derive Prim -- >>> :set -XGeneralizedNewtypeDeriving -XDataKinds -XUnboxedTuples -XPolyKinds -- >>>--- >>> import qualified Data.Vector.Unboxed         as U--- >>> import qualified Data.Vector.Primitive       as P--- >>> import qualified Data.Vector.Generic         as G--- >>> import qualified Data.Vector.Generic.Mutable as M+-- >>> import qualified Data.Vector.Generic         as VG+-- >>> import qualified Data.Vector.Generic.Mutable as VGM+-- >>> import qualified Data.Vector.Primitive       as VP+-- >>> import qualified Data.Vector.Unboxed         as VU -- >>>--- >>> newtype Foo = Foo Int deriving P.Prim+-- >>> newtype Foo = Foo Int deriving VP.Prim -- >>>--- >>> newtype instance U.MVector s Foo = MV_Int (P.MVector s Foo)--- >>> newtype instance U.Vector    Foo = V_Int  (P.Vector    Foo)--- >>> deriving via (U.UnboxViaPrim Foo) instance M.MVector MVector Foo--- >>> deriving via (U.UnboxViaPrim Foo) instance G.Vector  Vector  Foo--- >>> instance Unbox Foo+-- >>> newtype instance VU.MVector s Foo = MV_Int (VP.MVector s Foo)+-- >>> newtype instance VU.Vector    Foo = V_Int  (VP.Vector    Foo)+-- >>> deriving via (VU.UnboxViaPrim Foo) instance VGM.MVector VU.MVector Foo+-- >>> deriving via (VU.UnboxViaPrim Foo) instance VG.Vector   VU.Vector  Foo+-- >>> instance VU.Unbox Foo -- -- Second example is essentially same but with a twist. Instead of -- using @Prim@ instance of data type, we use underlying instance of @Int@: -- -- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia -XMultiParamTypeClasses -- >>>--- >>> import qualified Data.Vector.Unboxed         as U--- >>> import qualified Data.Vector.Primitive       as P--- >>> import qualified Data.Vector.Generic         as G--- >>> import qualified Data.Vector.Generic.Mutable as M+-- >>> import qualified Data.Vector.Generic         as VG+-- >>> import qualified Data.Vector.Generic.Mutable as VGM+-- >>> import qualified Data.Vector.Primitive       as VP+-- >>> import qualified Data.Vector.Unboxed         as VU -- >>> -- >>> newtype Foo = Foo Int -- >>>--- >>> newtype instance U.MVector s Foo = MV_Int (P.MVector s Int)--- >>> newtype instance U.Vector    Foo = V_Int  (P.Vector    Int)--- >>> deriving via (U.UnboxViaPrim Int) instance M.MVector MVector Foo--- >>> deriving via (U.UnboxViaPrim Int) instance G.Vector  Vector  Foo--- >>> instance Unbox Foo+-- >>> newtype instance VU.MVector s Foo = MV_Int (VP.MVector s Int)+-- >>> newtype instance VU.Vector    Foo = V_Int  (VP.Vector    Int)+-- >>> deriving via (VU.UnboxViaPrim Int) instance VGM.MVector VU.MVector Foo+-- >>> deriving via (VU.UnboxViaPrim Int) instance VG.Vector   VU.Vector  Foo+-- >>> instance VU.Unbox Foo -- -- @since 0.13.0.0 newtype UnboxViaPrim a = UnboxViaPrim a@@ -304,6 +304,7 @@ -- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia -- >>> :set -XMultiParamTypeClasses -XTypeOperators -XFlexibleInstances -- >>> import qualified Data.Vector.Unboxed         as VU+-- >>> import qualified Data.Vector.Unboxed.Mutable as MVU -- >>> import qualified Data.Vector.Generic         as VG -- >>> import qualified Data.Vector.Generic.Mutable as VGM -- >>> :{@@ -316,8 +317,8 @@ --   {-# INLINE fromURepr #-} -- newtype instance VU.MVector s (Foo a) = MV_Foo (VU.MVector s (Int, a)) -- newtype instance VU.Vector    (Foo a) = V_Foo  (VU.Vector    (Int, a))--- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VGM.MVector MVector (Foo a)--- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VG.Vector  Vector  (Foo a)+-- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VGM.MVector MVU.MVector (Foo a)+-- deriving via (Foo a `VU.As` (Int, a)) instance VU.Unbox a => VG.Vector   VU.Vector   (Foo a) -- instance VU.Unbox a => VU.Unbox (Foo a) -- :} --@@ -325,8 +326,8 @@ -- It's also possible to use generic-based instance for 'IsoUnbox' -- which should work for all product types. ----- >>> :set -XTypeFamilies -XStandaloneDeriving -XDerivingVia -XDeriveGeneric--- >>> :set -XMultiParamTypeClasses -XTypeOperators -XFlexibleInstances+-- >>> :set -XMultiParamTypeClasses -XTypeOperators -XFlexibleInstances -XDeriveGeneric+-- >>> :set -XDerivingVia -- >>> import qualified Data.Vector.Unboxed         as VU -- >>> import qualified Data.Vector.Generic         as VG -- >>> import qualified Data.Vector.Generic.Mutable as VGM
src/Data/Vector/Unboxed/Mutable.hs view
@@ -70,9 +70,7 @@ import Data.Vector.Fusion.Util ( delayed_min ) import Control.Monad.Primitive -import Prelude hiding ( length, null, replicate, reverse, map, read,-                        take, drop, splitAt, init, tail,-                        zip, zip3, unzip, unzip3, foldr, foldl, mapM_ )+import Prelude ( Ord, Bool, Int, Maybe )  -- don't import an unused Data.Vector.Internal.Check #define NOT_VECTOR_MODULE@@ -601,3 +599,6 @@  #define DEFINE_MUTABLE #include "unbox-tuple-instances"++-- $setup+-- >>> import Prelude (Char, (*), ($))
tests/Tests/Bundle.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeOperators #-} module Tests.Bundle ( tests ) where  import Boilerplater
tests/Tests/Vector/Property.hs view
@@ -1,4 +1,5 @@ {-# LANGUAGE ConstraintKinds #-}+{-# LANGUAGE TypeOperators #-} module Tests.Vector.Property   ( CommonContext   , VanillaContext@@ -31,6 +32,7 @@ import Control.Monad.ST import qualified Data.Traversable as T (Traversable(..)) import Data.Orphans ()+import Data.Maybe import Data.Foldable (foldrM) import qualified Data.Vector.Generic as V import qualified Data.Vector.Generic.Mutable as MV
tests/Utilities.hs view
@@ -1,10 +1,13 @@+{-# LANGUAGE DefaultSignatures #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE GADTs #-}+{-# LANGUAGE TypeOperators #-} module Utilities where  import Test.QuickCheck  import Data.Foldable+import Data.Bifunctor import qualified Data.Vector as DV import qualified Data.Vector.Generic as DVG import qualified Data.Vector.Primitive as DVP@@ -14,7 +17,6 @@  import Control.Monad (foldM, foldM_, zipWithM, zipWithM_) import Control.Monad.Trans.Writer-import Data.Function (on) import Data.Functor.Identity import Data.List ( sortBy ) import Data.Maybe (catMaybes)@@ -67,68 +69,62 @@   unmodel :: Model a -> a    type EqTest a+  type instance EqTest a = Property   equal :: a -> a -> EqTest a+  default equal :: (Eq a, EqTest a ~ Property) => a -> a -> EqTest a+  equal x y = property (x == y) + instance (Eq a, TestData a) => TestData (S.Bundle v a) where   type Model (S.Bundle v a) = [Model a]   model   = map model  . S.toList   unmodel = S.fromList . map unmodel -  type EqTest (S.Bundle v a) = Property-  equal x y = property (x == y)- instance (Eq a, TestData a) => TestData (DV.Vector a) where   type Model (DV.Vector a) = [Model a]   model   = map model    . DV.toList   unmodel = DV.fromList . map unmodel -  type EqTest (DV.Vector a) = Property-  equal x y = property (x == y)- instance (Eq a, DVP.Prim a, TestData a) => TestData (DVP.Vector a) where   type Model (DVP.Vector a) = [Model a]   model   = map model    . DVP.toList   unmodel = DVP.fromList . map unmodel -  type EqTest (DVP.Vector a) = Property-  equal x y = property (x == y)- instance (Eq a, DVS.Storable a, TestData a) => TestData (DVS.Vector a) where   type Model (DVS.Vector a) = [Model a]   model   = map model    . DVS.toList   unmodel = DVS.fromList . map unmodel -  type EqTest (DVS.Vector a) = Property-  equal x y = property (x == y)- instance (Eq a, DVU.Unbox a, TestData a) => TestData (DVU.Vector a) where   type Model (DVU.Vector a) = [Model a]   model   = map model    . DVU.toList   unmodel = DVU.fromList . map unmodel -  type EqTest (DVU.Vector a) = Property-  equal x y = property (x == y)- #define id_TestData(ty) \ instance TestData ty where { \   type Model ty = ty;        \   model = id;                \-  unmodel = id;              \-                             \-  type EqTest ty = Property; \-  equal x y = property (x == y) }+  unmodel = id }             \  id_TestData(()) id_TestData(Bool) id_TestData(Int)-id_TestData(Float)-id_TestData(Double) id_TestData(Ordering) -bimapEither :: (a -> b) -> (c -> d) -> Either a c -> Either b d-bimapEither f _ (Left a) = Left (f a)-bimapEither _ g (Right c) = Right (g c)+instance TestData Float where+  type Model Float = Float+  model = id+  unmodel = id +  equal x y = property (x == y || (isNaN x && isNaN y))++instance TestData Double where+  type Model Double = Double+  model = id+  unmodel = id++  equal x y = property (x == y || (isNaN x && isNaN y))+ -- Functorish models -- All of these need UndecidableInstances although they are actually well founded. Oh well. instance (Eq a, TestData a) => TestData (Maybe a) where@@ -136,57 +132,36 @@   model = fmap model   unmodel = fmap unmodel -  type EqTest (Maybe a) = Property-  equal x y = property (x == y)- instance (Eq a, TestData a, Eq b, TestData b) => TestData (Either a b) where   type Model (Either a b) = Either (Model a) (Model b)-  model = bimapEither model model-  unmodel = bimapEither unmodel unmodel--  type EqTest (Either a b) = Property-  equal x y = property (x == y)+  model = bimap model model+  unmodel = bimap unmodel unmodel  instance (Eq a, TestData a) => TestData [a] where   type Model [a] = [Model a]   model = fmap model   unmodel = fmap unmodel -  type EqTest [a] = Property-  equal x y = property (x == y)- instance (Eq a, TestData a) => TestData (Identity a) where   type Model (Identity a) = Identity (Model a)   model = fmap model   unmodel = fmap unmodel -  type EqTest (Identity a) = Property-  equal = (property .) . on (==) runIdentity- instance (Eq a, TestData a, Eq b, TestData b, Monoid a) => TestData (Writer a b) where   type Model (Writer a b) = Writer (Model a) (Model b)   model = mapWriter model   unmodel = mapWriter unmodel -  type EqTest (Writer a b) = Property-  equal = (property .) . on (==) runWriter- instance (Eq a, Eq b, TestData a, TestData b) => TestData (a,b) where   type Model (a,b) = (Model a, Model b)   model (a,b) = (model a, model b)   unmodel (a,b) = (unmodel a, unmodel b) -  type EqTest (a,b) = Property-  equal x y = property (x == y)- instance (Eq a, Eq b, Eq c, TestData a, TestData b, TestData c) => TestData (a,b,c) where   type Model (a,b,c) = (Model a, Model b, Model c)   model (a,b,c) = (model a, model b, model c)   unmodel (a,b,c) = (unmodel a, unmodel b, unmodel c) -  type EqTest (a,b,c) = Property-  equal x y = property (x == y)- instance (Arbitrary a, Show a, TestData a, TestData b) => TestData (a -> b) where   type Model (a -> b) = Model a -> Model b   model f = model . f . unmodel@@ -311,9 +286,6 @@  ifilter :: (Int -> a -> Bool) -> [a] -> [a] ifilter f = map snd . withIndexFirst filter f--mapMaybe :: (a -> Maybe b) -> [a] -> [b]-mapMaybe f = catMaybes . map f  imapMaybe :: (Int -> a -> Maybe b) -> [a] -> [b] imapMaybe f = catMaybes . withIndexFirst map f
tests/doctests.hs view
@@ -1,4 +1,38 @@ import Test.DocTest (doctest) +-- Doctests are weirdly fragile. For example running tests for module+-- A (D.V.Unboxed.Base) could cause tests in unrelated woudle B+-- (D.V.Storable) to start failing with weird errors.+--+-- In order to avoid this one would want to run doctests with+-- per-module granularity but this cause another sort of problems!+-- When we load only single module and use import doctests then some+-- data types may come from built library and some from ghci session.+--+-- This could be remedied by running doctests for groups of modules.+-- This _is_ convoluted setup but doctests now works for GHC9.4 main :: IO ()-main = doctest [ "-Iinclude" , "-Iinternal" , "-XHaskell2010" , "src/Data" ]+main = mapM_ run modGroups+  where+    run mods = do+      mapM_ putStrLn mods+      doctest $ ["-Iinclude", "-Iinternal", "-XHaskell2010"] ++ mods+    --+    modGroups =+      [ [ "src/Data/Vector/Storable/Mutable.hs"+        , "src/Data/Vector/Storable.hs"+        ]+      , [ "src/Data/Vector.hs"+        , "src/Data/Vector/Mutable.hs"+        ]+      , [ "src/Data/Vector/Generic.hs"+        , "src/Data/Vector/Generic/Mutable.hs"+        ]+      , [ "src/Data/Vector/Primitive.hs"+        , "src/Data/Vector/Primitive/Mutable.hs"+        ]+      , [ "src/Data/Vector/Unboxed.hs"+        , "src/Data/Vector/Unboxed/Mutable.hs"+        , "src/Data/Vector/Unboxed/Base.hs"+        ]+      ]
vector.cabal view
@@ -1,10 +1,13 @@ Name:           vector-Version:        0.13.0.0+Version:        0.13.1.0 -- don't forget to update the changelog file! License:        BSD3 License-File:   LICENSE Author:         Roman Leshchinskiy <rl@cse.unsw.edu.au> Maintainer:     Haskell Libraries Team <libraries@haskell.org>+                Alexey Kuleshevich <alexey@kuleshevi.ch>,+                Aleksey Khudyakov <alexey.skladnoy@gmail.com>,+                Andrew Lelechenko <andrew.lelechenko@gmail.com> Copyright:      (c) Roman Leshchinskiy 2008-2012,                     Alexey Kuleshevich 2020-2022,                     Aleksey Khudyakov 2020-2022,@@ -45,8 +48,11 @@   GHC == 8.6.5,   GHC == 8.8.4,   GHC == 8.10.7,-  GHC == 9.0.1,-  GHC == 9.2.3+  GHC == 9.0.2,+  GHC == 9.2.8,+  GHC == 9.4.6,+  GHC == 9.6.2+    Cabal-Version:  >= 1.10 Build-Type:     Simple@@ -139,9 +145,9 @@   Install-Includes:         vector.h -  Build-Depends: base >= 4.9 && < 4.17-               , primitive >= 0.6.4.0 && < 0.8-               , deepseq >= 1.1 && < 1.5+  Build-Depends: base >= 4.9 && < 4.20+               , primitive >= 0.6.4.0 && < 0.10+               , deepseq >= 1.1 && < 1.6                , vector-stream >= 0.1 && < 0.2    Ghc-Options: -O2 -Wall@@ -272,8 +278,8 @@     buildable: True   build-depends:         base      -any-      , doctest   >=0.15 && <0.21-      , primitive >= 0.6.4.0 && < 0.8+      , doctest   >=0.15 && <0.23+      , primitive >= 0.6.4.0 && < 0.10       , vector    -any  test-suite vector-inspection@@ -288,7 +294,7 @@                     Inspect.DerivingVia.OtherFoo   build-depends:         base                     -any-      , primitive                >= 0.6.4.0 && < 0.8+      , primitive                >= 0.6.4.0 && < 0.10       , vector                   -any       , tasty       , tasty-inspection-testing >= 0.1