vector-sized 1.5.0 → 1.6.1
raw patch · 13 files changed
+147/−128 lines, 13 filesdep +indexed-traversabledep ~basedep ~vectornew-uploader
Dependencies added: indexed-traversable
Dependency ranges changed: base, vector
Files
- changelog.md +14/−0
- package.yaml +0/−32
- src/Data/Vector/Generic/Mutable/Sized.hs +0/−5
- src/Data/Vector/Generic/Sized.hs +63/−17
- src/Data/Vector/Mutable/Sized.hs +0/−5
- src/Data/Vector/Primitive/Mutable/Sized.hs +0/−5
- src/Data/Vector/Primitive/Sized.hs +3/−8
- src/Data/Vector/Sized.hs +20/−9
- src/Data/Vector/Storable/Mutable/Sized.hs +0/−5
- src/Data/Vector/Storable/Sized.hs +18/−9
- src/Data/Vector/Unboxed/Mutable/Sized.hs +0/−5
- src/Data/Vector/Unboxed/Sized.hs +18/−9
- vector-sized.cabal +11/−19
changelog.md view
@@ -2,6 +2,20 @@ ## WIP +## [1.6.1]++- Fix build against Stackage nightly for GHC 9.4.5+- Future-proof against future Prelude `foldl'` (thanks Bodigrim!)++## [1.6.0] - 2022-01-22++- Add instances of `FunctorWithIndex`, `FoldableWithIndex` and+ `TraversableWithIndex` for `Vector n a`.+- Drop support for GHC older than 8.10+- Safe construction of vectors from linked lists (https://github.com/expipiplus1/vector-sized/pull/88)++Thanks to @sheaf and @kozross+ ## [1.5.0] - 2021-08-25 - Change indexes used by `accum` from `Int` to `Finite`.
− package.yaml
@@ -1,32 +0,0 @@-name: vector-sized-version: 1.5.0-synopsis: Size tagged vectors-description: Please see README.md-category: Data-author: Joe Hermaszewski-maintainer: whats.our.vector.victor@monoid.al-copyright: 2016 Joe Hermaszewski-license: BSD3-github: expipiplus1/vector-sized--extra-source-files:-- package.yaml-- readme.md-- changelog.md-- default.nix--dependencies:-- base >=4.9 && <5-- vector >=0.11 && <0.13-- deepseq >=1.1 && <1.5-- finite-typelits >=0.1-- primitive >=0.5 && <0.8-- indexed-list-literals >=0.2.0.0-- adjunctions >=4.3 && <4.5-- distributive >=0.5 && <0.7-- comonad >=4 && <6-- hashable >=1.2.4.0-- binary >=0.8.3.0--library:- source-dirs: src
src/Data/Vector/Generic/Mutable/Sized.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}@@ -68,10 +67,8 @@ , unsafeModify , unsafeSwap , unsafeExchange-#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors , nextPermutation-#endif -- ** Filling and copying , set , copy@@ -386,7 +383,6 @@ unsafeExchange (MVector v) = VGM.unsafeExchange v {-# inline unsafeExchange #-} -#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors -- | Compute the next permutation (in lexicographic order) of a given vector@@ -395,7 +391,6 @@ => MVector v n (PrimState m) e -> m Bool nextPermutation (MVector v) = VGM.nextPermutation v {-# inline nextPermutation #-}-#endif -- ** Filling and copying
src/Data/Vector/Generic/Sized.hs view
@@ -9,13 +9,12 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE PatternSynonyms #-} {-# LANGUAGE ViewPatterns #-}-{-# LANGUAGE CPP #-}+{-# LANGUAGE StandaloneDeriving #-}+{-# LANGUAGE GADTs #-} {-# LANGUAGE UndecidableInstances #-} {-# LANGUAGE AllowAmbiguousTypes #-}--#if MIN_VERSION_base(4,12,0)+{-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE NoStarIsType #-}-#endif {-# OPTIONS_GHC -Wno-orphans #-} {-|@@ -66,6 +65,8 @@ , empty , singleton , fromTuple+ , BuildVector(..)+ , pattern Build , replicate , replicate' , generate@@ -280,17 +281,18 @@ import qualified Data.Functor.Rep as Rep import Data.Distributive import Prelude- hiding (length, replicate, (++), head, last, init, tail, take,+ hiding (Foldable(..), replicate, (++), head, last, init, tail, take, drop, splitAt, reverse, map, concatMap, zipWith, zipWith3, zip,- zip3, unzip, unzip3, elem, notElem, foldl, foldl1, foldr, foldr1,- all, any, and, or, sum, product, maximum, minimum, scanl, scanl1,+ zip3, unzip, unzip3, notElem,+ all, any, and, or, scanl, scanl1, scanr, scanr1, mapM, mapM_, sequence, sequence_)-- import Data.IndexedListLiterals hiding (toList, fromList) import Data.Hashable (Hashable(..)) import qualified Data.IndexedListLiterals as ILL import Data.Vector.Unboxed (Unbox)+import qualified Data.Traversable.WithIndex as ITraversable+import qualified Data.Foldable.WithIndex as IFoldable+import qualified Data.Functor.WithIndex as IFunctor instance (KnownNat n, VG.Vector v a, Read (v a)) => Read (Vector v n a) where readPrec = parens $ prec 10 $ do@@ -324,9 +326,7 @@ -- @'join' :: Vector n (Vector n a) -> Vector n a@ gets the /diagonal/ from -- a square "matrix". instance KnownNat n => Monad (Vector Boxed.Vector n) where- return = replicate xs >>= f = imap (\i x -> f x `index` i) xs- (>>) = seq -- | Non-empty sized vectors are lawful comonads. --@@ -369,11 +369,6 @@ -- 'Monoid' will dodge the 'KnownNat' constraint. instance (Monoid m, VG.Vector v m, KnownNat n) => Monoid (Vector v n m) where mempty = replicate mempty-#if MIN_VERSION_base(4,11,0)- -- begone, non-canonical mappend!-#else- mappend = zipWith mappend-#endif mconcat vs = generate $ mconcat . flip fmap vs . flip index instance KnownNat n => Distributive (Vector Boxed.Vector n) where@@ -653,16 +648,43 @@ singleton a = Vector (VG.singleton a) {-# inline singleton #-} --- | /O(n)/ Construct a vector in a type-safe manner.+-- | /O(n)/ Construct a vector in a type-safe manner using a tuple. -- @ -- fromTuple (1,2) :: Vector v 2 Int -- fromTuple ("hey", "what's", "going", "on") :: Vector v 4 String -- @+--+-- @since 1.6.0 fromTuple :: forall v a input length. (VG.Vector v a, IndexedListLiterals input length a, KnownNat length) => input -> Vector v length a fromTuple = Vector . VG.fromListN (fromIntegral $ natVal $ Proxy @length) . ILL.toList +infixr 5 :<++-- | @since 1.6.0+data BuildVector (n :: Nat) a where+ -- | @since 1.6.0+ Nil :: BuildVector 0 a+ -- | @since 1.6.0+ (:<) :: a -> BuildVector n a -> BuildVector (1 + n) a++-- | @since 1.6.0+deriving instance Show a => Show (BuildVector n a)++-- | /O(n)/ Construct a vector in a type-safe manner using a sized linked list.+-- @+-- Build (1 :< 2 :< 3 :< Nil) :: Vector v 3 Int+-- Build ("not" :< "much" :< Nil) :: Vector v 2 String+-- @+-- Can also be used as a pattern.+--+-- @since 1.6.0+pattern Build :: VG.Vector v a => BuildVector n a -> Vector v n a+pattern Build build <- ( ( \ ( Vector v ) -> unsafeCoerce $ VG.toList v ) -> build )+ where+ Build vec = Vector . VG.fromList . unsafeCoerce $ vec+ -- | /O(n)/ Construct a vector with the same element in each position where the -- length is inferred from the type. replicate :: forall v n a. (KnownNat n, VG.Vector v a)@@ -2017,3 +2039,27 @@ instance (VG.Vector v a, Bits (v a), FiniteBits a, KnownNat n) => FiniteBits (Vector v n a) where finiteBitSize _ = finiteBitSize @a undefined * fromIntegral (natVal (Proxy @n)) +-- | @since 1.6.0+instance IFunctor.FunctorWithIndex (Finite n) (Vector Boxed.Vector n) where+ {-# INLINEABLE imap #-}+ imap = imap++-- | @since 1.6.0+instance IFoldable.FoldableWithIndex (Finite n) (Vector Boxed.Vector n) where+ {-# INLINEABLE ifoldMap #-}+ ifoldMap f = ifoldl (\acc ix x -> acc `mappend` f ix x) mempty+ {-# INLINEABLE ifoldMap' #-}+ ifoldMap' f = ifoldl' (\acc ix x -> acc `mappend` f ix x) mempty+ {-# INLINEABLE ifoldr #-}+ ifoldr = ifoldr+ {-# INLINEABLE ifoldl #-}+ ifoldl f x = ifoldl (\acc ix -> f ix acc) x+ {-# INLINEABLE ifoldr' #-}+ ifoldr' = ifoldr'+ {-# INLINEABLE ifoldl' #-}+ ifoldl' f x = ifoldl' (\acc ix -> f ix acc) x++-- | @since 1.6.0+instance ITraversable.TraversableWithIndex (Finite n) (Vector Boxed.Vector n) where+ {-# INLINEABLE itraverse #-}+ itraverse f = traverse (uncurry f) . indexed
src/Data/Vector/Mutable/Sized.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-}@@ -64,10 +63,8 @@ , unsafeModify , unsafeSwap , unsafeExchange-#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors , nextPermutation-#endif -- ** Filling and copying , set , copy@@ -378,7 +375,6 @@ unsafeExchange = VGM.unsafeExchange {-# inline unsafeExchange #-} -#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors -- | Compute the next permutation (lexicographically) of a given vector@@ -387,7 +383,6 @@ => MVector n (PrimState m) e -> m Bool nextPermutation = VGM.nextPermutation {-# inline nextPermutation #-}-#endif -- ** Filling and copying
src/Data/Vector/Primitive/Mutable/Sized.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-}@@ -64,10 +63,8 @@ , unsafeModify , unsafeSwap , unsafeExchange-#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors , nextPermutation-#endif -- ** Filling and copying , set , copy@@ -379,7 +376,6 @@ unsafeExchange = VGM.unsafeExchange {-# inline unsafeExchange #-} -#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors -- | Compute the next permutation (lexicographically) of a given vector@@ -388,7 +384,6 @@ => MVector n (PrimState m) e -> m Bool nextPermutation = VGM.nextPermutation {-# inline nextPermutation #-}-#endif -- ** Filling and copying
src/Data/Vector/Primitive/Sized.hs view
@@ -6,11 +6,7 @@ {-# LANGUAGE ScopedTypeVariables #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE PatternSynonyms #-}-{-# LANGUAGE CPP #-}--#if MIN_VERSION_base(4,12,0) {-# LANGUAGE NoStarIsType #-}-#endif {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -225,16 +221,15 @@ import Data.Primitive (Prim) import Data.Proxy import Control.Monad.Primitive-import Prelude hiding ( length, null,+import Prelude hiding ( Foldable(..), 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,- all, any, and, or, sum, product, maximum, minimum,+ notElem,+ all, any, and, or, scanl, scanl1, scanr, scanr1, enumFromTo, enumFromThenTo, mapM, mapM_, sequence, sequence_,
src/Data/Vector/Sized.hs view
@@ -8,11 +8,7 @@ {-# LANGUAGE TypeApplications #-} {-# LANGUAGE GADTs #-} {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE CPP #-}--#if MIN_VERSION_base(4,12,0) {-# LANGUAGE NoStarIsType #-}-#endif {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -63,6 +59,8 @@ , empty , singleton , fromTuple+ , BuildVector(..)+ , pattern Build , replicate , replicate' , generate@@ -243,6 +241,7 @@ ) where import qualified Data.Vector.Generic.Sized as V+import Data.Vector.Generic.Sized ( BuildVector(..) ) import qualified Data.Vector as VU import qualified Data.Vector.Mutable.Sized as VM import GHC.TypeLits@@ -250,16 +249,15 @@ import Data.Proxy import Data.IndexedListLiterals hiding (toList, fromList) import Control.Monad.Primitive-import Prelude hiding ( length, null,+import Prelude hiding ( Foldable(..), 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,- all, any, and, or, sum, product, maximum, minimum,+ notElem,+ all, any, and, or, scanl, scanl1, scanr, scanr1, enumFromTo, enumFromThenTo, mapM, mapM_, sequence, sequence_,@@ -486,15 +484,28 @@ singleton = V.singleton {-# inline singleton #-} --- | /O(n)/ Construct a vector in a type safe manner.+-- | /O(n)/ Construct a vector in a type safe manner using a tuple. -- @ -- fromTuple (1,2) :: Vector 2 Int -- fromTuple ("hey", "what's", "going", "on") :: Vector 4 String -- @+--+-- @since 1.6.0 fromTuple :: forall input length ty. (IndexedListLiterals input length ty, KnownNat length) => input -> Vector length ty fromTuple = V.fromTuple++-- | /O(n)/ Construct a vector in a type-safe manner using a sized linked list.+-- @+-- Build (1 :< 2 :< 3 :< Nil) :: Vector 3 Int+-- Build ("not" :< "much" :< Nil) :: Vector 2 String+-- @+-- Can also be used as a pattern.+--+-- @since 1.6.0+pattern Build :: V.BuildVector n a -> Vector n a+pattern Build build = V.Build build -- | /O(n)/ Construct a vector with the same element in each position where the -- length is inferred from the type.
src/Data/Vector/Storable/Mutable/Sized.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE RankNTypes #-}@@ -64,10 +63,8 @@ , unsafeModify , unsafeSwap , unsafeExchange-#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors , nextPermutation-#endif -- ** Filling and copying , set , copy@@ -379,7 +376,6 @@ unsafeExchange = VGM.unsafeExchange {-# inline unsafeExchange #-} -#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors -- | Compute the next permutation (lexicographically) of a given vector@@ -388,7 +384,6 @@ => MVector n (PrimState m) e -> m Bool nextPermutation = VGM.nextPermutation {-# inline nextPermutation #-}-#endif -- ** Filling and copying
src/Data/Vector/Storable/Sized.hs view
@@ -9,11 +9,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE CPP #-}--#if MIN_VERSION_base(4,12,0) {-# LANGUAGE NoStarIsType #-}-#endif {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -64,6 +60,7 @@ , empty , singleton , fromTuple+ , pattern Build , replicate , replicate' , generate@@ -252,16 +249,15 @@ import Data.Proxy import Control.Monad.Primitive import Foreign.Storable-import Prelude hiding ( length, null,+import Prelude hiding ( Foldable(..), 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,- all, any, and, or, sum, product, maximum, minimum,+ notElem,+ all, any, and, or, scanl, scanl1, scanr, scanr1, enumFromTo, enumFromThenTo, mapM, mapM_, sequence, sequence_,@@ -495,16 +491,29 @@ singleton = V.singleton {-# inline singleton #-} --- | /O(n)/ Construct a vector in a type safe manner+-- | /O(n)/ Construct a vector in a type safe manner using a tuple. -- @ -- fromTuple (1,2) :: Vector 2 Int -- fromTuple ("hey", "what's", "going", "on") :: Vector 4 String -- @+--+-- @since 1.6.0 fromTuple :: forall a input length. (Storable a, IndexedListLiterals input length a, KnownNat length) => input -> Vector length a fromTuple = V.fromTuple {-# inline fromTuple #-}++-- | /O(n)/ Construct a vector in a type-safe manner using a sized linked list.+-- @+-- Build (1 :< 2 :< 3 :< Nil) :: Vector 3 Int+-- Build ("not" :< "much" :< Nil) :: Vector 2 String+-- @+-- Can also be used as a pattern.+--+-- @since 1.6.0+pattern Build :: Storable a => V.BuildVector n a -> Vector n a+pattern Build vec = V.Build vec -- | /O(n)/ Construct a vector with the same element in each position where the -- length is inferred from the type.
src/Data/Vector/Unboxed/Mutable/Sized.hs view
@@ -1,4 +1,3 @@-{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}@@ -69,10 +68,8 @@ , unsafeModify , unsafeSwap , unsafeExchange-#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors , nextPermutation-#endif -- ** Filling and copying , set , copy@@ -391,7 +388,6 @@ unsafeExchange = VGM.unsafeExchange {-# inline unsafeExchange #-} -#if MIN_VERSION_vector(0,12,0) -- * Modifying vectors -- | Compute the next permutation (lexicographically) of a given vector@@ -400,7 +396,6 @@ => MVector n (PrimState m) e -> m Bool nextPermutation = VGM.nextPermutation {-# inline nextPermutation #-}-#endif -- ** Filling and copying
src/Data/Vector/Unboxed/Sized.hs view
@@ -9,11 +9,7 @@ {-# LANGUAGE GADTs #-} {-# LANGUAGE TypeApplications #-} {-# LANGUAGE AllowAmbiguousTypes #-}-{-# LANGUAGE CPP #-}--#if MIN_VERSION_base(4,12,0) {-# LANGUAGE NoStarIsType #-}-#endif {-| This module re-exports the functionality in 'Data.Vector.Generic.Sized'@@ -64,6 +60,7 @@ , empty , singleton , fromTuple+ , pattern Build , replicate , replicate' , generate@@ -254,16 +251,15 @@ import Data.Proxy import Control.Monad.Primitive import Data.Vector.Unboxed (Unbox)-import Prelude hiding ( length, null,+import Prelude hiding ( Foldable(..), 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,- all, any, and, or, sum, product, maximum, minimum,+ notElem,+ all, any, and, or, scanl, scanl1, scanr, scanr1, enumFromTo, enumFromThenTo, mapM, mapM_, sequence, sequence_,@@ -496,16 +492,29 @@ singleton = V.singleton {-# inline singleton #-} --- | /O(n)/ Construct a vector in a type safe manner+-- | /O(n)/ Construct a vector in a type safe manner using a tuple. -- @ -- fromTuple (1,2) :: Vector 2 Int -- fromTuple ("hey", "what's", "going", "on") :: Vector 4 String -- @+--+-- @since 1.6.0 fromTuple :: forall a input length. (Unbox a, IndexedListLiterals input length a, KnownNat length) => input -> Vector length a fromTuple = V.fromTuple {-# inline fromTuple #-}++-- | /O(n)/ Construct a vector in a type-safe manner using a sized linked list.+-- @+-- Build (1 :< 2 :< 3 :< Nil) :: Vector 3 Int+-- Build ("not" :< "much" :< Nil) :: Vector 2 String+-- @+-- Can also be used as a pattern.+--+-- @since 1.6.0+pattern Build :: Unbox a => V.BuildVector n a -> Vector n a+pattern Build vec = V.Build vec -- | /O(n)/ Construct a vector with the same element in each position where the -- length is inferred from the type.
vector-sized.cabal view
@@ -1,26 +1,19 @@-cabal-version: 1.12---- This file has been generated from package.yaml by hpack version 0.34.4.------ see: https://github.com/sol/hpack------ hash: 8cc33c7ff1b35236dcaed143ba951337eb4f12e3c53c616fa15ec2a073c0942b-+cabal-version: 3.0 name: vector-sized-version: 1.5.0+version: 1.6.1 synopsis: Size tagged vectors description: Please see README.md category: Data homepage: https://github.com/expipiplus1/vector-sized#readme bug-reports: https://github.com/expipiplus1/vector-sized/issues-author: Joe Hermaszewski+author: Ellie Hermaszewska maintainer: whats.our.vector.victor@monoid.al-copyright: 2016 Joe Hermaszewski-license: BSD3+copyright: 2016 Ellie Hermaszewska+license: BSD-3-Clause license-file: LICENSE build-type: Simple+tested-with: GHC ==8.10.7 || ==9.0.1 || ==9.2.1 extra-source-files:- package.yaml readme.md changelog.md default.nix@@ -43,20 +36,19 @@ Data.Vector.Storable.Sized Data.Vector.Unboxed.Mutable.Sized Data.Vector.Unboxed.Sized- other-modules:- Paths_vector_sized hs-source-dirs: src build-depends: adjunctions >=4.3 && <4.5- , base >=4.9 && <5+ , base >=4.14 && <5 , binary >=0.8.3.0 , comonad >=4 && <6- , deepseq >=1.1 && <1.5+ , deepseq >=1.1 && <1.6 , distributive >=0.5 && <0.7 , finite-typelits >=0.1 , hashable >=1.2.4.0 , indexed-list-literals >=0.2.0.0- , primitive >=0.5 && <0.8- , vector >=0.11 && <0.13+ , primitive >=0.5 && <0.10+ , indexed-traversable >=0.1.2 && <0.2+ , vector >=0.12 && <0.14 default-language: Haskell2010