fixed-vector-hetero 0.1.0.0 → 0.2.0.0
raw patch · 5 files changed
+103/−29 lines, 5 filesdep ~fixed-vectorPVP ok
version bump matches the API change (PVP)
Dependency ranges changed: fixed-vector
API changes (from Hackage documentation)
- Data.Vector.HFixed.Class: instance (GHVector f, Functor (Fun (GElems f))) => GHVector (M1 i c f)
- Data.Vector.HFixed.Class: instance (GHVector f, GHVector g, Arity xs, GElems f ~ xs, Arity ys, GElems g ~ ys) => GHVector (f :*: g)
+ Data.Vector.HFixed: elementCh :: (Index n (Elems v), a ~ ValueAt n (Elems v), HVector v, HVector w, Elems w ~ NewElems n (Elems v) b, Functor f) => n -> (a -> f b) -> (v -> f w)
+ Data.Vector.HFixed: monomorphizeF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> x) -> v f -> ContVec (Len (ElemsF v)) x
+ Data.Vector.HFixed: zipMonoF :: (HVectorF v, ArityC c (ElemsF v)) => Proxy c -> (forall a. c a => f a -> f a -> f a) -> v f -> v f -> v f
+ Data.Vector.HFixed.Class: instance (GHVector f, Arity (GElems f)) => GHVector (M1 i c f)
+ Data.Vector.HFixed.Class: instance (GHVector f, GHVector g, Arity (GElems f), Arity (GElems g)) => GHVector (f :*: g)
+ Data.Vector.HFixed.Class: lensChF :: (Index n xs, Functor f) => n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r)
+ Data.Vector.HFixed.Cont: zipMonoF :: ArityC c xs => Proxy c -> (forall a. c a => f a -> f a -> f a) -> ContVecF xs f -> ContVecF xs f -> ContVecF xs f
- Data.Vector.HFixed: monomorphize :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. a -> x) -> v -> ContVec (Len (Elems v)) x
+ Data.Vector.HFixed: monomorphize :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> x) -> v -> ContVec (Len (Elems v)) x
- Data.Vector.HFixed.Class: applyTy :: Arity xs => (forall a as. t (a : as) -> (f a, t as)) -> t xs -> Fn (Wrap f xs) b -> b
+ Data.Vector.HFixed.Class: applyTy :: Arity xs => (forall a as. t (a : as) -> (f a, t as)) -> t xs -> ContVecF xs f
- Data.Vector.HFixed.Class: class Arity n => Index (n :: *) (xs :: [*]) where type family ValueAt n xs :: *
+ Data.Vector.HFixed.Class: class Arity n => Index (n :: *) (xs :: [*]) where type family ValueAt n xs :: * type family NewElems n xs a :: [*]
- Data.Vector.HFixed.Cont: applyTy :: Arity xs => (forall a as. t (a : as) -> (f a, t as)) -> t xs -> Fn (Wrap f xs) b -> b
+ Data.Vector.HFixed.Cont: applyTy :: Arity xs => (forall a as. t (a : as) -> (f a, t as)) -> t xs -> ContVecF xs f
Files
- ChangeLog +8/−0
- Data/Vector/HFixed.hs +44/−1
- Data/Vector/HFixed/Class.hs +31/−22
- Data/Vector/HFixed/Cont.hs +16/−4
- fixed-vector-hetero.cabal +4/−2
+ ChangeLog view
@@ -0,0 +1,8 @@++Changes in 0.2.0.0++ * Type changing lenses added++ * zipMonoF added++ * types of monomorphize and monomorphizeF corrected
Data/Vector/HFixed.hs view
@@ -32,8 +32,10 @@ , index , set , element+ , elementCh #if __GLASGOW_HASKELL__ >= 708 , elementTy+ , elementChTy #endif -- * Generic constructors , mk0@@ -52,8 +54,10 @@ , replicate , replicateM , zipMono+ , zipMonoF , zipFold , monomorphize+ , monomorphizeF -- * Vector parametrized with type constructor , mapFunctor , sequence@@ -153,6 +157,18 @@ element n f v = inspect v $ lensF n f construct +-- | Type changing Twan van Laarhoven's lens for i'th element.+elementCh :: ( Index n (Elems v)+ , a ~ ValueAt n (Elems v)+ , HVector v+ , HVector w+ , Elems w ~ NewElems n (Elems v) b+ , Functor f)+ => n -> (a -> f b) -> (v -> f w)+{-# INLINE elementCh #-}+elementCh n f v = inspect v+ $ lensChF n f construct+ #if __GLASGOW_HASKELL__ >= 708 -- | Twan van Laarhoven's lens for i'th element. GHC >= 7.8 elementTy :: forall n a f v proxy.@@ -164,6 +180,18 @@ => proxy n -> (a -> f a) -> (v -> f v) {-# INLINE elementTy #-} elementTy _ = element (undefined :: ToPeano n)++-- | Type changing Twan van Laarhoven's lens for i'th element.+elementChTy :: forall a b f n v w proxy.+ ( Index (ToPeano n) (Elems v)+ , a ~ ValueAt (ToPeano n) (Elems v)+ , HVector v+ , HVector w+ , Elems w ~ NewElems (ToPeano n) (Elems v) b+ , Functor f)+ => proxy n -> (a -> f b) -> (v -> f w)+{-# INLINE elementChTy #-}+elementChTy _ = elementCh (undefined :: ToPeano n) #endif @@ -325,12 +353,20 @@ {-# INLINE unfoldr #-} unfoldr c f b0 = C.vector $ C.unfoldr c f b0 +-- | Zip two heterogeneous vectors zipMono :: (HVector v, ArityC c (Elems v)) => Proxy c -> (forall a. c a => a -> a -> a) -> v -> v -> v {-# INLINE zipMono #-} zipMono c f v u = C.vector $ C.zipMono c f (C.cvec v) (C.cvec u) +-- | Zip two heterogeneous vectors+zipMonoF :: (HVectorF v, ArityC c (ElemsF v))+ => Proxy c -> (forall a. c a => f a -> f a -> f a) -> v f -> v f -> v f+{-# INLINE zipMonoF #-}+zipMonoF c f v u+ = C.vectorF $ C.zipMonoF c f (C.cvecF v) (C.cvecF u)+ zipFold :: (HVector v, ArityC c (Elems v), Monoid m) => Proxy c -> (forall a. c a => a -> a -> m) -> v -> v -> m {-# INLINE zipFold #-}@@ -339,10 +375,17 @@ -- | Convert heterogeneous vector to homogeneous monomorphize :: (HVector v, ArityC c (Elems v))- => Proxy c -> (forall a. a -> x)+ => Proxy c -> (forall a. c a => a -> x) -> v -> F.ContVec (Len (Elems v)) x {-# INLINE monomorphize #-} monomorphize c f = C.monomorphize c f . C.cvec++-- | Convert heterogeneous vector to homogeneous+monomorphizeF :: (HVectorF v, ArityC c (ElemsF v))+ => Proxy c -> (forall a. c a => f a -> x)+ -> v f -> F.ContVec (Len (ElemsF v)) x+{-# INLINE monomorphizeF #-}+monomorphizeF c f = C.monomorphizeF c f . C.cvecF -- | Generic equality for heterogeneous vectors
Data/Vector/HFixed/Class.hs view
@@ -88,7 +88,7 @@ import Data.Vector.Fixed.Cont (ToPeano,ToNat,NatIso) #endif import qualified Data.Vector.Fixed as F-import qualified Data.Vector.Fixed.Cont as F (apFun)+import qualified Data.Vector.Fixed.Cont as F (curryFirst) import qualified Data.Vector.Fixed.Unboxed as U import qualified Data.Vector.Fixed.Primitive as P import qualified Data.Vector.Fixed.Storable as S@@ -179,8 +179,7 @@ -- elements are wrapped in the newtype constructor. applyTy :: (forall a as. t (a ': as) -> (f a, t as)) -> t xs- -> Fn (Wrap f xs) b- -> b+ -> ContVecF xs f -- | Size of type list as integer. arity :: p xs -> Int@@ -232,7 +231,7 @@ apply _ _ = ContVec unFun applyM _ _ = return (ContVec unFun) accumTy _ f t = f t- applyTy _ _ b = b+ applyTy _ _ = ContVecF unTFun {-# INLINE accum #-} {-# INLINE apply #-} {-# INLINE applyM #-}@@ -257,7 +256,7 @@ vec <- applyM f t' return $ cons a vec accumTy f g t = \a -> accumTy f g (f t a)- applyTy f t h = case f t of (a,u) -> applyTy f u (h a)+ applyTy f t = case f t of (a,u) -> consF a (applyTy f u) {-# INLINE accum #-} {-# INLINE apply #-} {-# INLINE applyM #-}@@ -343,7 +342,7 @@ instance HomArity n a => HomArity (S n) a where toHeterogeneous f- = Fun $ \a -> unFun $ toHeterogeneous (F.apFun f a)+ = Fun $ \a -> unFun $ toHeterogeneous (F.curryFirst f a) toHomogeneous (f :: Fun (a ': HomList n a) r) = F.Fun $ \a -> F.unFun (toHomogeneous $ curryFun f a :: F.Fun n a r) {-# INLINE toHeterogeneous #-}@@ -641,7 +640,10 @@ -- | Indexing of vectors class F.Arity n => Index (n :: *) (xs :: [*]) where+ -- | Type at position n type ValueAt n xs :: *+ -- | List of types with n'th element replaced by /a/.+ type NewElems n xs a :: [*] -- | Getter function for vectors getF :: n -> Fun xs (ValueAt n xs) -- | Putter function. It applies value @x@ to @n@th parameter of@@ -650,6 +652,9 @@ -- | Helper for implementation of lens lensF :: (Functor f, v ~ ValueAt n xs) => n -> (v -> f v) -> Fun xs r -> Fun xs (f r)+ -- | Helper for type-changing lens+ lensChF :: (Functor f)+ => n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r) witWrapIndex :: WitWrapIndex f n xs @@ -662,26 +667,32 @@ instance Arity xs => Index Z (x ': xs) where- type ValueAt Z (x ': xs) = x+ type ValueAt Z (x ': xs) = x+ type NewElems Z (x ': xs) a = a ': xs getF _ = Fun $ \x -> unFun (pure x :: Fun xs x) putF _ x f = constFun $ curryFun f x- lensF _ = lensWorkerF- {-# INLINE getF #-}- {-# INLINE putF #-}- {-# INLINE lensF #-}+ lensF _ = lensWorkerF+ lensChF _ = lensWorkerF+ {-# INLINE getF #-}+ {-# INLINE putF #-}+ {-# INLINE lensF #-}+ {-# INLINE lensChF #-} witWrapIndex :: forall f. WitWrapIndex f Z (x ': xs) witWrapIndex = case witWrapped :: WitWrapped f xs of WitWrapped -> WitWrapIndex {-# INLINE witWrapIndex #-} instance Index n xs => Index (S n) (x ': xs) where- type ValueAt (S n) (x ': xs) = ValueAt n xs- getF _ = constFun $ getF (undefined :: n)- putF _ x = stepFun $ putF (undefined :: n) x- lensF _ f = stepFun $ lensF (undefined :: n) f- {-# INLINE getF #-}- {-# INLINE putF #-}- {-# INLINE lensF #-}+ type ValueAt (S n) (x ': xs) = ValueAt n xs+ type NewElems (S n) (x ': xs) a = x ': NewElems n xs a+ getF _ = constFun $ getF (undefined :: n)+ putF _ x = stepFun $ putF (undefined :: n) x+ lensF _ f = stepFun $ lensF (undefined :: n) f+ lensChF _ f = stepFun $ lensChF (undefined :: n) f+ {-# INLINE getF #-}+ {-# INLINE putF #-}+ {-# INLINE lensF #-}+ {-# INLINE lensChF #-} witWrapIndex :: forall f. WitWrapIndex f (S n) (x ': xs) witWrapIndex = case witWrapIndex :: WitWrapIndex f n xs of WitWrapIndex -> WitWrapIndex@@ -761,7 +772,7 @@ -- We simply skip metadata-instance (GHVector f, Functor (Fun (GElems f))) => GHVector (M1 i c f) where+instance (GHVector f, Arity (GElems f)) => GHVector (M1 i c f) where type GElems (M1 i c f) = GElems f gconstruct = fmap M1 gconstruct ginspect v = ginspect (unM1 v)@@ -769,9 +780,7 @@ {-# INLINE ginspect #-} -instance ( GHVector f, GHVector g- , Arity xs, GElems f ~ xs- , Arity ys, GElems g ~ ys+instance ( GHVector f, GHVector g, Arity (GElems f), Arity (GElems g) ) => GHVector (f :*: g) where type GElems (f :*: g) = GElems f ++ GElems g
Data/Vector/HFixed/Cont.hs view
@@ -60,6 +60,7 @@ , replicate , replicateM , zipMono+ , zipMonoF , zipFold , monomorphize , monomorphizeF@@ -265,7 +266,7 @@ => f (ContVec xs) -> ContVecF xs f {-# INLINE distribute #-} distribute f0- = ContVecF $ \(TFun fun) -> applyTy step start fun+ = applyTy step start where step :: forall a as. T_distribute f (a ': as) -> (f a, T_distribute f as) step (T_distribute v) = ( fmap (\(Cons x _) -> x) v@@ -278,7 +279,7 @@ => f (ContVecF xs g) -> ContVecF xs (f `Compose` g) {-# INLINE distributeF #-} distributeF f0- = ContVecF $ \(TFun fun) -> applyTy step start fun+ = applyTy step start where step :: forall a as. T_distributeF f g (a ': as) -> ((Compose f g) a, T_distributeF f g as) step (T_distributeF v) = ( Compose $ fmap (\(ConsF x _) -> x) v@@ -358,8 +359,8 @@ instance Arity xs => HVectorF (VecListF xs) where type ElemsF (VecListF xs) = xs- constructF = conVecF- inspectF v (TFun f) = applyTy step (TF_insp v) f+ constructF = conVecF+ inspectF v = inspectF (applyTy step (TF_insp v)) where step :: TF_insp f (a ': as) -> (f a, TF_insp f as) step (TF_insp (ConsF a xs)) = (a, TF_insp xs)@@ -478,6 +479,17 @@ (T_zipMono (vector cvecA) (vector cvecB) witAllInstances :: T_zipMono c xs) data T_zipMono c xs = T_zipMono (VecList xs) (VecList xs) (WitAllInstances c xs)++-- | Zip two heterogeneous vectors+zipMonoF :: forall xs f c. (ArityC c xs)+ => Proxy c -> (forall a. c a => f a -> f a -> f a) -> ContVecF xs f -> ContVecF xs f -> ContVecF xs f+{-# INLINE zipMonoF #-}+zipMonoF _ f cvecA cvecB+ = applyTy (\(T_zipMonoF (ConsF a va) (ConsF b vb) (WitAllInstancesCons w)) ->+ (f a b, T_zipMonoF va vb w))+ (T_zipMonoF (vectorF cvecA) (vectorF cvecB) witAllInstances :: T_zipMonoF c f xs)++data T_zipMonoF c f xs = T_zipMonoF (VecListF xs f) (VecListF xs f) (WitAllInstances c xs) -- | Zip vector and fold result using monoid
fixed-vector-hetero.cabal view
@@ -1,5 +1,5 @@ Name: fixed-vector-hetero-Version: 0.1.0.0+Version: 0.2.0.0 Synopsis: Generic heterogeneous vectors Description: Generic heterogeneous vectors@@ -12,6 +12,8 @@ Homepage: http://github.org/Shimuuar/fixed-vector-hetero Category: Data Build-Type: Simple+extra-source-files:+ ChangeLog source-repository head type: git@@ -27,7 +29,7 @@ deepseq, transformers, ghc-prim,- fixed-vector >= 0.6.4,+ fixed-vector >= 0.7.0.0, primitive Exposed-modules: Data.Vector.HFixed