fixed-vector-hetero 0.6.0.0 → 0.6.1.0
raw patch · 8 files changed
+87/−62 lines, 8 filessetup-changedPVP: major bump suggested
API removals or changes: PVP suggests a major version bump
API changes (from Hackage documentation)
- Data.Vector.HFixed: data Proxy (t :: k) :: forall k. () => k -> Type
- Data.Vector.HFixed.Class: data Proxy (t :: k) :: forall k. () => k -> Type
- Data.Vector.HFixed.Class: instance (Data.Primitive.Types.Prim a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) Data.Type.Equality.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Primitive.Vec n a)
- Data.Vector.HFixed.Class: instance (Data.Vector.Fixed.Unboxed.Unbox n a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) Data.Type.Equality.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Unboxed.Vec n a)
- Data.Vector.HFixed.Class: instance (Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) Data.Type.Equality.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Boxed.Vec n a)
- Data.Vector.HFixed.Class: instance (Foreign.Storable.Storable a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) Data.Type.Equality.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Storable.Vec n a)
- Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k2) (xs :: k1). (TypeError ...) => Data.Vector.HFixed.Class.NoTypeCase 'GHC.Types.True a xs
- Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k2) (xs :: k1). Data.Vector.HFixed.Class.NoType a xs => Data.Vector.HFixed.Class.NoTypeCase 'GHC.Types.False a xs
- Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k2). Data.Vector.HFixed.Class.NoType a '[]
- Data.Vector.HFixed.TypeFuns: data Proxy (t :: k) :: forall k. () => k -> Type
+ Data.Vector.HFixed: data Proxy (t :: k)
+ Data.Vector.HFixed: foldMap :: (HVector v, ArityC c (Elems v), Monoid m) => Proxy c -> (forall a. c a => a -> m) -> v -> m
+ Data.Vector.HFixed: foldMapF :: (HVectorF v, ArityC c (ElemsF v), Monoid m) => Proxy c -> (forall a. c a => f a -> m) -> v f -> m
+ Data.Vector.HFixed: foldMapNatF :: (HVectorF v, Monoid m) => (forall a. f a -> m) -> v f -> m
+ Data.Vector.HFixed.Class: data Proxy (t :: k)
+ Data.Vector.HFixed.Class: instance (Data.Primitive.Types.Prim a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) GHC.Types.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Primitive.Vec n a)
+ Data.Vector.HFixed.Class: instance (Data.Vector.Fixed.Unboxed.Unbox n a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) GHC.Types.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Unboxed.Vec n a)
+ Data.Vector.HFixed.Class: instance (Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) GHC.Types.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Boxed.Vec n a)
+ Data.Vector.HFixed.Class: instance (Foreign.Storable.Storable a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeNats.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeNats.+ 1) GHC.Types.~ 'Data.Vector.Fixed.Cont.S (Data.Vector.Fixed.Cont.Peano n)) => Data.Vector.HFixed.Class.HVector (Data.Vector.Fixed.Storable.Vec n a)
+ Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k1) (xs :: k2). (TypeError ...) => Data.Vector.HFixed.Class.NoTypeCase 'GHC.Types.True a xs
+ Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k1) (xs :: k2). Data.Vector.HFixed.Class.NoType a xs => Data.Vector.HFixed.Class.NoTypeCase 'GHC.Types.False a xs
+ Data.Vector.HFixed.Class: instance forall k1 k2 (a :: k1). Data.Vector.HFixed.Class.NoType a '[]
+ Data.Vector.HFixed.Cont: foldMapF :: (Monoid m, ArityC c xs) => Proxy c -> (forall a. c a => f a -> m) -> ContVecF xs f -> m
+ Data.Vector.HFixed.Cont: foldMapNatF :: (Monoid m, Arity xs) => (forall a. f a -> m) -> ContVecF xs f -> m
+ Data.Vector.HFixed.TypeFuns: data Proxy (t :: k)
- Data.Vector.HFixed: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
+ Data.Vector.HFixed: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed: Proxy :: Proxy
+ Data.Vector.HFixed: Proxy :: Proxy (t :: k)
- Data.Vector.HFixed: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed: [runContVecF] :: ContVecF (xs :: [α]) (f :: α -> *) -> forall r. TFun f xs r -> r
- Data.Vector.HFixed.Class: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
+ Data.Vector.HFixed.Class: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Class: Proxy :: Proxy
+ Data.Vector.HFixed.Class: Proxy :: Proxy (t :: k)
- Data.Vector.HFixed.Class: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed.Class: [runContVecF] :: ContVecF (xs :: [α]) (f :: α -> *) -> forall r. TFun f xs r -> r
- Data.Vector.HFixed.Cont: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
+ Data.Vector.HFixed.Cont: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Cont: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed.Cont: [runContVecF] :: ContVecF (xs :: [α]) (f :: α -> *) -> forall r. TFun f xs r -> r
- Data.Vector.HFixed.TypeFuns: Proxy :: Proxy
+ Data.Vector.HFixed.TypeFuns: Proxy :: Proxy (t :: k)
Files
- ChangeLog.md +7/−0
- Data/Vector/HFixed.hs +36/−4
- Data/Vector/HFixed/Class.hs +4/−4
- Data/Vector/HFixed/Cont.hs +25/−1
- Data/Vector/HFixed/HVec.hs +6/−6
- Setup.hs +0/−33
- fixed-vector-hetero.cabal +7/−12
- test/doctests.hs +2/−2
ChangeLog.md view
@@ -1,3 +1,10 @@+Changes in 0.6.1.0++ * `foldMap`, `foldMapF`, `foldMapNatF` is added++ * GHC 9.0.1 compatibility++ Changes in 0.6.0.0 * Type class `TyLookup` and `tyLookup` & `tyLookupF` added for lookup up field
Data/Vector/HFixed.hs view
@@ -62,6 +62,7 @@ -- ** Folds & unfolds , foldr , foldl+ , foldMap , mapM_ -- ** Zips , zipWith@@ -100,8 +101,10 @@ -- ** Folds and unfolds , foldrF , foldlF+ , foldMapF , foldrNatF , foldlNatF+ , foldMapNatF -- ** Zips , zipWithF , zipWithNatF@@ -311,6 +314,16 @@ {-# INLINE foldl #-} foldl c f b0 = C.foldlF c (\b (Identity a) -> f b a) b0 . C.cvec +-- | Monoidal fold over heterogeneuous vector+--+-- >>> foldMap (Proxy @Show) show (12,'c',"str")+-- "12'c'\"str\""+foldMap+ :: (HVector v, ArityC c (Elems v), Monoid m)+ => Proxy c -> (forall a. c a => a -> m) -> v -> m+{-# INLINE foldMap #-}+foldMap c f = C.foldMapF c (\(Identity a) -> f a) . C.cvec+ -- | Right fold over heterogeneous vector foldrF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> b -> b) -> b -> v f -> b@@ -323,6 +336,15 @@ {-# INLINE foldlF #-} foldlF c f b0 = C.foldlF c f b0 . C.cvecF +-- | Monoidal fold over heterogeneous vector+--+-- >>> foldMapF (Proxy @Show) show (mk2F (Just 1) Nothing :: HVecF '[Int,Char] Maybe)+-- "Just 1Nothing"+foldMapF :: (HVectorF v, ArityC c (ElemsF v), Monoid m)+ => Proxy c -> (forall a. c a => f a -> m) -> v f -> m+{-# INLINE foldMapF #-}+foldMapF c f = C.foldMapF c f . C.cvecF+ -- | Right fold over heterogeneous vector foldrNatF :: (HVectorF v) => (forall a. f a -> b -> b) -> b -> v f -> b@@ -335,6 +357,15 @@ {-# INLINE foldlNatF #-} foldlNatF f b0 = C.foldlNatF f b0 . C.cvecF +-- | Monoidal fold over heterogeneous vector+--+-- >>> foldMapNatF (Sum . getConst) (mk2F (Const 1) (Const 2) :: HVecF '[Char,String] (Const Int))+-- Sum {getSum = 3}+foldMapNatF :: (HVectorF v, Monoid m)+ => (forall a. f a -> m) -> v f -> m+{-# INLINE foldMapNatF #-}+foldMapNatF f = C.foldMapNatF f . C.cvecF+ -- | Apply monadic action to every element in the vector mapM_ :: (HVector v, ArityC c (Elems v), Applicative f) => Proxy c -> (forall a. c a => a -> f ()) -> v -> f ()@@ -687,8 +718,9 @@ -- >>> import Prelude (Int,Double,String,Char,IO,(++),Maybe(..)) -- >>> import Prelude (Show(..),Read(..),read,Num(..),Monoid(..)) -- >>> import Prelude (print)--- >>> import Data.Complex (Complex(..))--- >>> import Data.Monoid (Sum(..),Product(..))--- >>> import Data.Maybe (fromMaybe)+-- >>> import Control.Applicative (Const(..))+-- >>> import Data.Complex (Complex(..))+-- >>> import Data.Monoid (Sum(..),Product(..))+-- >>> import Data.Maybe (fromMaybe) -- >>> import Data.Vector.HFixed.HVec (HVec,HVecF)--- >>> import GHC.Generics (Generic)+-- >>> import GHC.Generics (Generic)
Data/Vector/HFixed/Class.hs view
@@ -576,10 +576,10 @@ instance Index n xs => Index ('S n) (x : xs) where type ValueAt ('S n) (x : xs) = ValueAt n xs type NewElems ('S n) (x : xs) a = x : NewElems n xs a- getF _ = constFun $ getF (Proxy @ n)- putF _ x = stepTFun $ putF (Proxy @ n) x- lensF _ f = stepTFun $ lensF (Proxy @ n) f- lensChF _ f = stepTFun $ lensChF (Proxy @ n) f+ getF _ = constFun $ getF (Proxy @n)+ putF _ x = stepTFun $ putF (Proxy @n) x+ lensF _ f = stepTFun $ lensF (Proxy @n) f+ lensChF _ f = stepTFun $ lensChF (Proxy @n) f {-# INLINE getF #-} {-# INLINE putF #-} {-# INLINE lensF #-}
Data/Vector/HFixed/Cont.hs view
@@ -51,8 +51,10 @@ -- ** Folds and unfolds , foldlF , foldrF+ , foldMapF , foldlNatF , foldrNatF+ , foldMapNatF , unfoldrF -- ** Replicate variants , replicateF@@ -239,7 +241,7 @@ (\(T_List f) (Identity a) -> T_List (f . Cons a)) (\(T_List f) -> f Nil) (T_List id)- inspect = runContVecF . apply step+ inspect f = runContVecF (apply step f) where step :: VecList (a : as) -> (Identity a, VecList as) step (Cons a xs) = (Identity a, xs)@@ -292,6 +294,28 @@ ---------------------------------------------------------------- -- Folds ----------------------------------------------------------------++-- | Monoidal fold over vector+foldMapNatF+ :: (Monoid m, Arity xs)+ => (forall a. f a -> m) -> ContVecF xs f -> m+{-# INLINE foldMapNatF #-}+foldMapNatF f v+ = inspectF v+ $ accum (\(Const m) a -> Const (m <> f a))+ (\(Const m) -> m)+ (Const mempty)++-- | Monoidal fold over vector+foldMapF+ :: (Monoid m, ArityC c xs)+ => Proxy c -> (forall a. c a => f a -> m) -> ContVecF xs f -> m+{-# INLINE foldMapF #-}+foldMapF cls f v+ = inspectF v+ $ accumC cls (\(Const m) a -> Const (m <> f a))+ (\(Const m) -> m)+ (Const mempty) -- | Right fold over vector foldrF :: (ArityC c xs)
Data/Vector/HFixed/HVec.hs view
@@ -53,7 +53,7 @@ (\(T_con _ box) -> HVecF $ runBox len box) (T_con 0 (Box $ \_ -> return ())) where- len = arity (Proxy @ xs)+ len = arity (Proxy @xs) {-# INLINE constructF #-} data T_insp (xs :: [*]) = T_insp Int (SmallArray Any)@@ -80,11 +80,11 @@ showsPrec _ v = showChar '[' . ( foldr (.) id $ intersperse (showChar ',')- $ H.foldrF (Proxy @ Show) (\x xs -> showsPrec1 0 x : xs) [] v+ $ H.foldrF (Proxy @Show) (\x xs -> showsPrec1 0 x : xs) [] v ) . showChar ']' instance (Eq1 f, ArityC Eq xs) => Eq (HVecF xs f) where- v == u = getAll $ H.zipFoldF (Proxy @ Eq) (\x y -> All (eq1 x y)) v u+ v == u = getAll $ H.zipFoldF (Proxy @Eq) (\x y -> All (eq1 x y)) v u instance (Ord1 f, ArityC Eq xs, ArityC Ord xs) => Ord (HVecF xs f) where compare = H.zipFoldF (Proxy :: Proxy Ord) compare1 @@ -123,13 +123,13 @@ , ArityC Semigroup xs #endif ) => Monoid (HVec xs) where- mempty = H.replicate (Proxy @ Monoid) mempty- mappend = H.zipWith (Proxy @ Monoid) mappend+ mempty = H.replicate (Proxy @Monoid) mempty+ mappend = H.zipWith (Proxy @Monoid) mappend {-# INLINE mempty #-} {-# INLINE mappend #-} instance (ArityC Semigroup xs) => Semigroup (HVec xs) where- (<>) = H.zipWith (Proxy @ Semigroup) (<>)+ (<>) = H.zipWith (Proxy @Semigroup) (<>) {-# INLINE (<>) #-} instance (ArityC NFData xs) => NFData (HVec xs) where
− Setup.hs
@@ -1,33 +0,0 @@-{-# LANGUAGE CPP #-}-{-# OPTIONS_GHC -Wall #-}-module Main (main) where--#ifndef MIN_VERSION_cabal_doctest-#define MIN_VERSION_cabal_doctest(x,y,z) 0-#endif--#if MIN_VERSION_cabal_doctest(1,0,0)--import Distribution.Extra.Doctest ( defaultMainWithDoctests )-main :: IO ()-main = defaultMainWithDoctests "doctests"--#else--#ifdef MIN_VERSION_Cabal--- If the macro is defined, we have new cabal-install,--- but for some reason we don't have cabal-doctest in package-db------ Probably we are running cabal sdist, when otherwise using new-build--- workflow-#warning You are configuring this package without cabal-doctest installed. \- The doctests test-suite will not work as a result. \- To fix this, install cabal-doctest before configuring.-#endif--import Distribution.Simple--main :: IO ()-main = defaultMain--#endif
fixed-vector-hetero.cabal view
@@ -1,5 +1,5 @@ Name: fixed-vector-hetero-Version: 0.6.0.0+Version: 0.6.1.0 Synopsis: Library for working with product types generically Description: Library allow to work with arbitrary product types in generic@@ -13,7 +13,7 @@ Maintainer: Aleksey Khudyakov <alexey.skladnoy@gmail.com> Homepage: http://github.org/Shimuuar/fixed-vector-hetero Category: Data-Build-Type: Custom+Build-Type: Simple extra-source-files: ChangeLog.md @@ -22,20 +22,15 @@ || ==8.2.2 || ==8.4.4 || ==8.6.5- || ==8.8.3- || ==8.10.1+ || ==8.8.4+ || ==8.10.2+ || ==9.0.1 , GHCJS ==8.4 source-repository head type: git location: http://github.com/Shimuuar/fixed-vector-hetero -custom-setup- setup-depends:- base >=4.9 && <5,- Cabal >=1.10 && <3.3,- cabal-doctest >=1.0.6 && <1.1- Library -- Bigger context stack needed for HVector instances for large -- tuples@@ -61,8 +56,8 @@ hs-source-dirs: test default-language: Haskell2010 build-depends:- base >=4.9 && <5- , doctest >=0.15 && <0.17+ base >=4.9 && <5+ , doctest >=0.15 && <0.19 , fixed-vector >=1.0 , fixed-vector-hetero -any
test/doctests.hs view
@@ -1,6 +1,5 @@ module Main where -import Build_doctests (flags, pkgs, module_sources) import Data.Foldable (traverse_) import Test.DocTest (doctest) @@ -9,4 +8,5 @@ traverse_ putStrLn args doctest args where- args = flags ++ pkgs ++ module_sources+ args = ["Data"]+