fixed-vector-hetero 0.4.0.0 → 0.5.0.0
raw patch · 5 files changed
+43/−23 lines, 5 filesdep ~basePVP ok
version bump matches the API change (PVP)
Dependency ranges changed: base
API changes (from Hackage documentation)
- Data.Vector.HFixed: data Proxy k (t :: k) :: forall k. k -> *
- Data.Vector.HFixed.Class: data Proxy k (t :: k) :: forall k. k -> *
- Data.Vector.HFixed.Class: instance (Data.Primitive.Types.Prim a, Data.Vector.HFixed.Class.HomArity (Data.Vector.Fixed.Cont.Peano n) a, GHC.TypeLits.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeLits.+ 1) ~ '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.TypeLits.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeLits.+ 1) ~ '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.TypeLits.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeLits.+ 1) ~ '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.TypeLits.KnownNat n, Data.Vector.Fixed.Cont.Peano (n GHC.TypeLits.+ 1) ~ '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 (c x, Data.Vector.HFixed.Class.ArityC c xs) => Data.Vector.HFixed.Class.ArityC c (x : xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.Arity (x : xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.HVectorF (Data.Vector.HFixed.Class.ContVecF xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.Arity xs => GHC.Base.Applicative (Data.Vector.HFixed.Class.TFun f xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.Arity xs => GHC.Base.Functor (Data.Vector.HFixed.Class.TFun f xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.Arity xs => GHC.Base.Monad (Data.Vector.HFixed.Class.TFun f xs)
- Data.Vector.HFixed.Class: instance Data.Vector.HFixed.Class.ArityC c '[]
- Data.Vector.HFixed.Cont: instance Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.HVectorF (Data.Vector.HFixed.Cont.VecListF xs)
- Data.Vector.HFixed.TypeFuns: data Proxy k (t :: k) :: forall k. k -> *
+ Data.Vector.HFixed: data Proxy k (t :: k) :: forall k. () => k -> *
+ Data.Vector.HFixed.Class: data Proxy k (t :: k) :: forall k. () => 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) ~ '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.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.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.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 a (c :: a -> GHC.Types.Constraint) (x :: a) (xs :: [a]). (c x, Data.Vector.HFixed.Class.ArityC c xs) => Data.Vector.HFixed.Class.ArityC c (x : xs)
+ Data.Vector.HFixed.Class: instance forall α (c :: α -> GHC.Types.Constraint). Data.Vector.HFixed.Class.ArityC c '[]
+ Data.Vector.HFixed.Class: instance forall α (xs :: [α]) (f :: α -> *). Data.Vector.HFixed.Class.Arity xs => GHC.Base.Applicative (Data.Vector.HFixed.Class.TFun f xs)
+ Data.Vector.HFixed.Class: instance forall α (xs :: [α]) (f :: α -> *). Data.Vector.HFixed.Class.Arity xs => GHC.Base.Functor (Data.Vector.HFixed.Class.TFun f xs)
+ Data.Vector.HFixed.Class: instance forall α (xs :: [α]) (f :: α -> *). Data.Vector.HFixed.Class.Arity xs => GHC.Base.Monad (Data.Vector.HFixed.Class.TFun f xs)
+ Data.Vector.HFixed.Class: instance forall α (xs :: [α]) (x :: α). Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.Arity (x : xs)
+ Data.Vector.HFixed.Class: instance forall α (xs :: [α]). Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.HVectorF (Data.Vector.HFixed.Class.ContVecF xs)
+ Data.Vector.HFixed.Cont: instance forall α (xs :: [α]). Data.Vector.HFixed.Class.Arity xs => Data.Vector.HFixed.Class.HVectorF (Data.Vector.HFixed.Cont.VecListF xs)
+ Data.Vector.HFixed.HVec: instance Data.Vector.HFixed.Class.ArityC Data.Semigroup.Semigroup xs => Data.Semigroup.Semigroup (Data.Vector.HFixed.HVec.HVec xs)
+ Data.Vector.HFixed.TypeFuns: data Proxy k (t :: k) :: forall k. () => k -> *
- Data.Vector.HFixed: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF xs f
+ Data.Vector.HFixed: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
- Data.Vector.HFixed: [runContVecF] :: ContVecF xs f -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
- Data.Vector.HFixed: class Arity (xs :: [*])
+ Data.Vector.HFixed: class Arity (xs :: [α])
- Data.Vector.HFixed: class Arity (Elems v) => HVector v where type Elems v :: [*] type Elems v = GElems (Rep v) construct = fmap to gconstruct inspect v = ginspect (from v) where {
+ Data.Vector.HFixed: class Arity (Elems v) => HVector v where {
- Data.Vector.HFixed: class Arity (ElemsF v) => HVectorF (v :: (* -> *) -> *) where type ElemsF v :: [*] where {
+ Data.Vector.HFixed: class Arity (ElemsF v) => HVectorF (v :: (α -> *) -> *) where {
- Data.Vector.HFixed: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where type ValueAt n xs :: * where {
+ Data.Vector.HFixed: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where {
- Data.Vector.HFixed: newtype ContVecF xs f
+ Data.Vector.HFixed: newtype ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Class: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF xs f
+ Data.Vector.HFixed.Class: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
- Data.Vector.HFixed.Class: [runContVecF] :: ContVecF xs f -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed.Class: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
- Data.Vector.HFixed.Class: class Arity (xs :: [*])
+ Data.Vector.HFixed.Class: class Arity (xs :: [α])
- Data.Vector.HFixed.Class: class Arity (Elems v) => HVector v where type Elems v :: [*] type Elems v = GElems (Rep v) construct = fmap to gconstruct inspect v = ginspect (from v) where {
+ Data.Vector.HFixed.Class: class Arity (Elems v) => HVector v where {
- Data.Vector.HFixed.Class: class Arity (ElemsF v) => HVectorF (v :: (* -> *) -> *) where type ElemsF v :: [*] where {
+ Data.Vector.HFixed.Class: class Arity (ElemsF v) => HVectorF (v :: (α -> *) -> *) where {
- Data.Vector.HFixed.Class: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where type ValueAt n xs :: * type NewElems n xs a :: [*] where {
+ Data.Vector.HFixed.Class: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where {
- Data.Vector.HFixed.Class: lensChF :: (Index n xs, Functor f) => proxy n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r)
+ Data.Vector.HFixed.Class: lensChF :: (Index n xs, (Functor f)) => proxy n -> (ValueAt n xs -> f a) -> Fun (NewElems n xs a) r -> Fun xs (f r)
- Data.Vector.HFixed.Class: newtype ContVecF xs f
+ Data.Vector.HFixed.Class: newtype ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Cont: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF xs f
+ Data.Vector.HFixed.Cont: ContVecF :: (forall r. TFun f xs r -> r) -> ContVecF
- Data.Vector.HFixed.Cont: [runContVecF] :: ContVecF xs f -> forall r. TFun f xs r -> r
+ Data.Vector.HFixed.Cont: [runContVecF] :: ContVecF -> forall r. TFun f xs r -> r
- Data.Vector.HFixed.Cont: class Arity (xs :: [*])
+ Data.Vector.HFixed.Cont: class Arity (xs :: [α])
- Data.Vector.HFixed.Cont: class Arity (Elems v) => HVector v where type Elems v :: [*] type Elems v = GElems (Rep v) construct = fmap to gconstruct inspect v = ginspect (from v) where {
+ Data.Vector.HFixed.Cont: class Arity (Elems v) => HVector v where {
- Data.Vector.HFixed.Cont: class Arity (ElemsF v) => HVectorF (v :: (* -> *) -> *) where type ElemsF v :: [*] where {
+ Data.Vector.HFixed.Cont: class Arity (ElemsF v) => HVectorF (v :: (α -> *) -> *) where {
- Data.Vector.HFixed.Cont: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where type ValueAt n xs :: * where {
+ Data.Vector.HFixed.Cont: class ArityPeano n => Index (n :: PeanoNum) (xs :: [*]) where {
- Data.Vector.HFixed.Cont: data VecListF xs f
+ Data.Vector.HFixed.Cont: data VecListF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Cont: newtype ContVecF xs f
+ Data.Vector.HFixed.Cont: newtype ContVecF (xs :: [α]) (f :: α -> *)
- Data.Vector.HFixed.Cont: replicateF :: forall f c xs. ArityC c xs => Proxy c -> (forall a. c a => f a) -> ContVecF xs f
+ Data.Vector.HFixed.Cont: replicateF :: ArityC c xs => Proxy c -> (forall a. c a => f a) -> ContVecF xs f
- Data.Vector.HFixed.Cont: replicateNatF :: forall f xs. Arity xs => (forall a. f a) -> ContVecF xs f
+ Data.Vector.HFixed.Cont: replicateNatF :: Arity xs => (forall a. f a) -> ContVecF xs f
- Data.Vector.HFixed.Cont: zipWithF :: forall xs f g h c. (ArityC c xs) => Proxy c -> (forall a. c a => f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h
+ Data.Vector.HFixed.Cont: zipWithF :: (ArityC c xs) => Proxy c -> (forall a. c a => f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h
- Data.Vector.HFixed.Cont: zipWithNatF :: forall xs f g h. (Arity xs) => (forall a. f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h
+ Data.Vector.HFixed.Cont: zipWithNatF :: (Arity xs) => (forall a. f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g -> ContVecF xs h
Files
- ChangeLog.md +6/−0
- Data/Vector/HFixed/Class.hs +6/−8
- Data/Vector/HFixed/Cont.hs +15/−11
- Data/Vector/HFixed/HVec.hs +13/−1
- fixed-vector-hetero.cabal +3/−3
ChangeLog.md view
@@ -1,3 +1,9 @@+Changes in 0.5.0.0++ * GHC8.4 compatibility release. Semigroup instance is added for HVec+ + * Classes `Arity`, `ArityC`, and `HVectorF` are now polykinded+ Changes in 0.4.0.0 * Major rework of API. `Fun` and `TFun` are unified. `Fun ~ TFun Identity`.
Data/Vector/HFixed/Class.hs view
@@ -1,11 +1,8 @@ {-# LANGUAGE ConstraintKinds #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE DefaultSignatures #-}-{-# LANGUAGE ExplicitNamespaces #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE FlexibleInstances #-}-{-# LANGUAGE GADTs #-}-{-# LANGUAGE InstanceSigs #-} {-# LANGUAGE KindSignatures #-} {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE PolyKinds #-}@@ -90,7 +87,7 @@ -- | Type family for N-ary function. Types of function parameters are -- encoded as the list of types.-type family Fn (f :: * -> *) (as :: [*]) b where+type family Fn (f :: α -> *) (as :: [α]) b where Fn f '[] b = b Fn f (a : as) b = f a -> Fn f as b @@ -119,7 +116,7 @@ -- This is also somewhat a kitchen sink module. It contains -- witnesses which could be used to prove type equalities or to -- bring instance in scope.-class Arity (xs :: [*]) where+class Arity (xs :: [α]) where -- | Fold over /N/ elements exposed as N-ary function. accum :: (forall a as. t (a : as) -> f a -> t as) -- ^ Step function. Applies element to accumulator.@@ -226,9 +223,9 @@ -- | Type class for partially homogeneous vector where every element -- in the vector have same type constructor. Vector itself is -- parametrized by that constructor-class Arity (ElemsF v) => HVectorF (v :: (* -> *) -> *) where+class Arity (ElemsF v) => HVectorF (v :: (α -> *) -> *) where -- | Elements of the vector without type constructors- type ElemsF v :: [*]+ type ElemsF v :: [α] inspectF :: v f -> TFun f (ElemsF v) a -> a constructF :: TFun f (ElemsF v) (v f) @@ -346,7 +343,8 @@ type ContVec xs = ContVecF xs Identity -- | CPS-encoded partially heterogeneous vector.-newtype ContVecF xs f = ContVecF { runContVecF :: forall r. TFun f xs r -> r }+newtype ContVecF (xs :: [α]) (f :: α -> *) =+ ContVecF { runContVecF :: forall r. TFun f xs r -> r } instance Arity xs => HVectorF (ContVecF xs) where type ElemsF (ContVecF xs) = xs
Data/Vector/HFixed/Cont.hs view
@@ -145,7 +145,7 @@ mapNat f (ContVecF cont) = ContVecF $ cont . mapFF f {-# INLINE mapNat #-} -mapFF :: forall r f g xs. (Arity xs)+mapFF :: (Arity xs) => (forall a. f a -> g a) -> TFun g xs r -> TFun f xs r {-# INLINE mapFF #-} mapFF g (TFun f0) = accum@@ -163,7 +163,7 @@ = cont $ sequenceF_F constructF {-# INLINE sequenceF #-} -sequenceF_F :: forall f g xs r. (Applicative f, Arity xs)+sequenceF_F :: (Applicative f, Arity xs) => TFun g xs r -> TFun (f `Compose` g) xs (f r) {-# INLINE sequenceF_F #-} sequenceF_F (TFun f) =@@ -219,7 +219,7 @@ -- | List-like vector-data VecListF xs f where+data VecListF (xs :: [α]) (f :: α -> *) where NilF :: VecListF '[] f ConsF :: f x -> VecListF xs f -> VecListF (x : xs) f @@ -233,7 +233,7 @@ {-# INLINE constructF #-} {-# INLINE inspectF #-} -conVecF :: forall f xs. (Arity xs) => TFun f xs (VecListF xs f)+conVecF :: (Arity xs) => TFun f xs (VecListF xs f) {-# INLINE conVecF #-} conVecF = accum (\(TF_List f) a -> TF_List (f . ConsF a)) (\(TF_List f) -> f NilF)@@ -248,11 +248,11 @@ -- More combinators ---------------------------------------------------------------- -replicateNatF :: forall f xs. Arity xs => (forall a. f a) -> ContVecF xs f+replicateNatF :: Arity xs => (forall a. f a) -> ContVecF xs f {-# INLINE replicateNatF #-} replicateNatF f = apply (\Proxy -> (f, Proxy)) (Proxy) -replicateF :: forall f c xs. ArityC c xs => Proxy c -> (forall a. c a => f a) -> ContVecF xs f+replicateF :: ArityC c xs => Proxy c -> (forall a. c a => f a) -> ContVecF xs f {-# INLINE replicateF #-} replicateF cls f = applyC cls (\Proxy -> (f,Proxy)) Proxy @@ -338,7 +338,7 @@ ---------------------------------------------------------------- -- | Zip two heterogeneous vectors-zipWithF :: forall xs f g h c. (ArityC c xs)+zipWithF :: (ArityC c xs) => Proxy c -> (forall a. c a => f a -> g a -> h a) -> ContVecF xs f@@ -348,14 +348,18 @@ zipWithF cls f cvecA cvecB = applyC cls (\(T_zipWithF (ConsF a va) (ConsF b vb)) -> (f a b, T_zipWithF va vb))- (T_zipWithF (vectorF cvecA) (vectorF cvecB) :: T_zipWithF f g xs)+ (T_zipWithF (vectorF cvecA) (vectorF cvecB)) data T_zipWithF f g xs = T_zipWithF (VecListF xs f) (VecListF xs g) -- | Zip vector and fold result using monoid zipFoldF :: forall xs c m f. (ArityC c xs, Monoid m)- => Proxy c -> (forall a. c a => f a -> f a -> m) -> ContVecF xs f -> ContVecF xs f -> m+ => Proxy c+ -> (forall a. c a => f a -> f a -> m)+ -> ContVecF xs f+ -> ContVecF xs f+ -> m {-# INLINE zipFoldF #-} zipFoldF cls f cvecA cvecB = inspectF cvecB zipF@@ -370,7 +374,7 @@ -- | Zip two heterogeneous vectors-zipWithNatF :: forall xs f g h. (Arity xs)+zipWithNatF :: (Arity xs) => (forall a. f a -> g a -> h a) -> ContVecF xs f -> ContVecF xs g@@ -378,6 +382,6 @@ {-# INLINE zipWithNatF #-} zipWithNatF f cvecA cvecB = apply (\(T_zipNatF (ConsF a va) (ConsF b vb)) -> (f a b, T_zipNatF va vb))- (T_zipNatF (vectorF cvecA) (vectorF cvecB) :: T_zipNatF f g xs)+ (T_zipNatF (vectorF cvecA) (vectorF cvecB)) data T_zipNatF f g xs = T_zipNatF (VecListF xs f) (VecListF xs g)
Data/Vector/HFixed/HVec.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE DataKinds #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE GADTs #-}@@ -18,6 +19,7 @@ import Data.Functor.Identity (Identity(..)) import Data.Functor.Classes import Control.DeepSeq (NFData(..))+import Data.Semigroup (Semigroup(..)) import Data.Monoid (Monoid(..),All(..)) import Data.List (intersperse,intercalate) import Data.Primitive.SmallArray ( SmallArray, SmallMutableArray, newSmallArray@@ -115,11 +117,21 @@ compare = H.compare {-# INLINE compare #-} -instance (ArityC Monoid xs) => Monoid (HVec xs) where+instance (ArityC Monoid xs+-- NOTE: Sadly we cannot infer `ArityC Semigroup' xs from `ArityC Monoid xs'+-- Thus we have to specify both+#if MIN_VERSION_base(4,11,0)+ , ArityC Semigroup xs+#endif+ ) => Monoid (HVec xs) where 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) (<>)+ {-# INLINE (<>) #-} instance (ArityC NFData xs) => NFData (HVec xs) where rnf = H.rnf
fixed-vector-hetero.cabal view
@@ -1,5 +1,5 @@ Name: fixed-vector-hetero-Version: 0.4.0.0+Version: 0.5.0.0 Synopsis: Generic heterogeneous vectors Description: Generic heterogeneous vectors@@ -16,8 +16,8 @@ ChangeLog.md source-repository head- type: hg- location: http://bitbucket.org/Shimuuar/fixed-vector-hetero+ type: git+ location: http://github.com/Shimuuar/fixed-vector-hetero Library -- Bigger context stack needed for HVector instances for large