packages feed

fixed-vector 0.6.4.0 → 0.7.0.0

raw patch · 5 files changed

+134/−36 lines, 5 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

- Data.Vector.Fixed.Cont: apFun :: Fun (S n) a b -> a -> Fun n a b
- Data.Vector.Fixed.Cont: hideLast :: Arity n => Fun (S n) a b -> Fun n a (a -> b)
+ Data.Vector.Fixed: concat :: (Vector v a, Vector u a, Vector w a, (Add (Dim v) (Dim u)) ~ Dim w) => v a -> u a -> w a
+ Data.Vector.Fixed: set :: (Vector v a, Index k (Dim v)) => k -> a -> v a -> v a
+ Data.Vector.Fixed.Cont: WitSum :: WitSum n k a b
+ Data.Vector.Fixed.Cont: concat :: (Arity n, Arity k, Arity (Add n k)) => ContVec n a -> ContVec k a -> ContVec (Add n k) a
+ Data.Vector.Fixed.Cont: curryFirst :: Fun (S n) a b -> a -> Fun n a b
+ Data.Vector.Fixed.Cont: curryLast :: Arity n => Fun (S n) a b -> Fun n a (a -> b)
+ Data.Vector.Fixed.Cont: curryMany :: Arity n => Fun (Add n k) a b -> Fun n a (Fun k a b)
+ Data.Vector.Fixed.Cont: data WitSum n k a b
+ Data.Vector.Fixed.Cont: putF :: Index k n => k -> a -> Fun n a r -> Fun n a r
+ Data.Vector.Fixed.Cont: uncurryFirst :: (a -> Fun n a b) -> Fun (S n) a b
+ Data.Vector.Fixed.Cont: uncurryMany :: Arity n => Fun n a (Fun k a b) -> Fun (Add n k) a b
+ Data.Vector.Fixed.Cont: witSum :: Arity n => WitSum n k a b
+ Data.Vector.Fixed.Cont: withFun :: (Fun n a b -> Fun n a b) -> Fun (S n) a b -> Fun (S n) a b

Files

ChangeLog view
@@ -1,3 +1,12 @@+Changes in 0.7.0.0++  * Type level addition for unary numbers added++  * `concat` function added++  * More consistent naming for functions for working with `Fun`++ Changes in 0.6.4.0    * Isomorphism between Peano numbers and Nat added. (GHC >= 7.8)
Data/Vector/Fixed.hs view
@@ -82,11 +82,13 @@   , tail   , cons   , snoc+  , concat   , reverse     -- ** Indexing & lenses   , C.Index   , (!)   , index+  , set   , element   , elementTy     -- ** Comparison@@ -164,7 +166,7 @@  import Prelude hiding ( replicate,map,zipWith,maximum,minimum,and,or,all,any                       , foldl,foldr,foldl1,length,sum,reverse,scanl,scanl1-                      , head,tail,mapM,mapM_,sequence,sequence_+                      , head,tail,mapM,mapM_,sequence,sequence_,concat                       )  
Data/Vector/Fixed/Cont.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE TypeOperators         #-} {-# LANGUAGE CPP                   #-} {-# LANGUAGE EmptyDataDecls        #-} {-# LANGUAGE DeriveDataTypeable    #-}@@ -7,6 +8,7 @@ {-# LANGUAGE TypeFamilies          #-} {-# LANGUAGE ScopedTypeVariables   #-} {-# LANGUAGE Rank2Types            #-}+{-# LANGUAGE GADTs #-} -- Needed for NatIso #if __GLASGOW_HASKELL__ >= 708 {-# LANGUAGE DataKinds, TypeOperators, UndecidableInstances #-}@@ -19,6 +21,7 @@     -- * Type-level numbers     S   , Z+  , Add     -- ** Isomorphism between Peano number and Nats     -- $natiso #if __GLASGOW_HASKELL__ >= 708@@ -39,12 +42,17 @@   , Arity(..)   , apply   , applyM+  , WitSum(..)     -- ** Combinators-  , apFun-  , apLast   , constFun-  , hideLast+  , curryFirst+  , uncurryFirst+  , curryLast+  , curryMany+  , uncurryMany+  , apLast   , shuffleFun+  , withFun     -- * Vector type class   , Dim   , Vector(..)@@ -70,6 +78,7 @@   , cons   , consV   , snoc+  , concat   , mk1   , mk2   , mk3@@ -140,7 +149,7 @@  import Prelude hiding ( replicate,map,zipWith,maximum,minimum,and,or,any,all                       , foldl,foldr,foldl1,length,sum,reverse,scanl,scanl1-                      , head,tail,mapM,mapM_,sequence,sequence_+                      , head,tail,mapM,mapM_,sequence,sequence_,concat                       )  @@ -153,6 +162,12 @@ -- | Successor of n data S n deriving Typeable +-- | Type family for sum of unary natural numbers.+type family Add n m :: *++type instance Add  Z    n = n+type instance Add (S n) k = S (Add n k)+ type N1 = S Z type N2 = S N1 type N3 = S N2@@ -180,11 +195,11 @@ -- | Convert Nat number to Peano represenation type family ToPeano (b :: Nat) :: * where   ToPeano 0 = Z-  ToPeano n = S (ToPeano (n-1))+  ToPeano n = S (ToPeano (n - 1))  instance NatIso  Z 0 where instance ( NatIso k (n - 1)-         , ToPeano (n-1) ~ k+         , ToPeano (n - 1) ~ k          , ToPeano  n    ~ S k          , n ~ (1 + (n - 1))    -- n is positive          ) => NatIso (S k) n where@@ -274,10 +289,17 @@   gunfoldF :: (Arity n, Data a)            => (forall b x. Data b => c (b -> x) -> c x)            -> T_gunfold c r a n -> c r+  -- | Proof that `Fn (n+k) a b ~ Fn n a (Fn k a b)`+  witSum :: WitSum n k a b + newtype T_gunfold c r a n = T_gunfold (c (Fn n a r)) +-- | Value that carry proof that `Fn (Add n k) a b ~ Fn n a (Fn k a b)`+data WitSum n k a b where+  WitSum :: (Fn (Add n k) a b ~ Fn n a (Fn k a b)) => WitSum n k a b + -- | Apply all parameters to the function. apply :: Arity n       => (forall k. t (S k) -> (a, t k)) -- ^ Get value to apply to function@@ -309,6 +331,8 @@   gunfoldF _ (T_gunfold c) = c   {-# INLINE reverseF #-}   {-# INLINE gunfoldF #-}+  witSum = WitSum+  {-# INLINE witSum #-}  instance Arity n => Arity (S n) where   accum     f g t = \a -> accum  f g (f t a)@@ -321,11 +345,18 @@   {-# INLINE applyFun  #-}   {-# INLINE applyFunM #-}   {-# INLINE arity     #-}-  reverseF f   = Fun $ \a -> unFun (reverseF $ fmap ($ a) $ hideLast f)+  reverseF f   = Fun $ \a -> unFun (reverseF $ apLast f a)   gunfoldF f c = gunfoldF f (apGunfold f c)   {-# INLINE reverseF #-}   {-# INLINE gunfoldF #-}+  witSum = witSumWorker+  {-# INLINE witSum #-} +witSumWorker :: forall n k a b. Arity n => WitSum (S n) k a b+{-# INLINE witSumWorker #-}+witSumWorker = case witSum :: WitSum n k a b of+                 WitSum -> WitSum+ apGunfold :: Data a           => (forall b x. Data b => c (b -> x) -> c x)           -> T_gunfold c r a (S n)@@ -339,32 +370,64 @@ -- Combinators ---------------------------------------------------------------- --- | Apply single parameter to function-apFun :: Fun (S n) a b -> a -> Fun n a b-apFun (Fun f) x = Fun (f x)-{-# INLINE apFun #-}---- | Apply last parameter to function. Unlike 'apFun' we need to---   traverse all parameters but last hence 'Arity' constraint.-apLast :: Arity n => Fun (S n) a b -> a -> Fun n a b-apLast f x = fmap ($ x) $ hideLast f-{-# INLINE apLast #-}---- | Add one parameter to function which is ignored.+-- | Prepend ignored parameter to function constFun :: Fun n a b -> Fun (S n) a b constFun (Fun f) = Fun $ \_ -> f {-# INLINE constFun #-} --- | Move last parameter into function result-hideLast :: forall n a b. Arity n => Fun (S n) a b -> Fun n a (a -> b)-{-# INLINE hideLast #-}-hideLast (Fun f0) = Fun $ accum (\(T_fun f) a -> T_fun (f a))-                                (\(T_fun f)   -> f)-                                (T_fun f0 :: T_fun a b n)+-- | Curry first parameter of n-ary function+curryFirst :: Fun (S n) a b -> a -> Fun n a b+curryFirst (Fun f) x = Fun (f x)+{-# INLINE curryFirst #-} +-- | Uncurry first parameter of n-ary function+uncurryFirst :: (a -> Fun n a b) -> Fun (S n) a b+uncurryFirst f = Fun $ fmap unFun f+{-# INLINE uncurryFirst #-}++-- | Curry last parameter of n-ary function+curryLast :: forall n a b. Arity n => Fun (S n) a b -> Fun n a (a -> b)+{-# INLINE curryLast #-}+curryLast (Fun f0) = Fun $ accum (\(T_fun f) a -> T_fun (f a))+                                 (\(T_fun f)   -> f)+                                 (T_fun f0 :: T_fun a b n)+ newtype T_fun a b n = T_fun (Fn (S n) a b) +-- | Curry /n/ first parameters of n-ary function+curryMany :: forall n k a b. Arity n+          => Fun (Add n k) a b -> Fun n a (Fun k a b)+{-# INLINE curryMany #-}+curryMany (Fun f0) = Fun $ accum+  (\(T_curry f) a -> T_curry (f a))+  (\(T_curry f) -> Fun f :: Fun k a b)+  ( T_curry f0 :: T_curry a b k n) +newtype T_curry a b k n = T_curry (Fn (Add n k) a b)++-- | Uncurry /n/ first parameters of n-ary function+uncurryMany :: forall n k a b. Arity n+            => Fun n a (Fun k a b) -> Fun (Add n k) a b+{-# INLINE uncurryMany #-}+uncurryMany f =+  case witSum :: WitSum n k a b of+    WitSum ->+      case fmap unFun f :: Fun n a (Fn k a b) of+        Fun g -> Fun g+++-- | Apply last parameter to function. Unlike 'apFun' we need to+--   traverse all parameters but last hence 'Arity' constraint.+apLast :: Arity n => Fun (S n) a b -> a -> Fun n a b+apLast f x = fmap ($ x) $ curryLast f+{-# INLINE apLast #-}++-- | Recursive step for the function+withFun :: (Fun n a b -> Fun n a b) -> Fun (S n) a b -> Fun (S n) a b+withFun f fun = Fun $ \a -> unFun $ f $ curryFirst fun a+{-# INLINE withFun #-}++ -- | Move function parameter to the result of N-ary function. shuffleFun :: forall n a b r. Arity n            => (b -> Fun n a r) -> Fun n a (b -> r)@@ -417,23 +480,28 @@ --   compile time. class Index k n where   getF  :: k -> Fun n a a+  putF  :: k -> a -> Fun n a r -> Fun n a r   lensF :: Functor f => k -> (a -> f a) -> Fun n a r -> Fun n a (f r)  instance Arity n => Index Z (S n) where   getF  _       = Fun $ \(a :: a) -> unFun (pure a :: Fun n a a)+  putF  _ a (Fun f) = Fun $ \_ -> f a   lensF _ f fun = Fun $ \(a :: a) -> unFun $-    (\g -> g <$> f a) <$> shuffleFun (apFun fun)+    (\g -> g <$> f a) <$> shuffleFun (curryFirst fun)   {-# INLINE getF  #-}+  {-# INLINE putF  #-}   {-# INLINE lensF #-}  instance Index k n => Index (S k) (S n) where   getF  _       = Fun $ \(_::a) -> unFun (getF  (undefined :: k) :: Fun n a a)-  lensF _ f fun = Fun $ \a      -> unFun (lensF (undefined :: k) f (apFun fun a))+  putF _ a (f :: Fun (S n) a b)+    = withFun (putF (undefined :: k) a) f+  lensF _ f fun = Fun $ \a -> unFun (lensF (undefined :: k) f (curryFirst fun a))   {-# INLINE getF  #-}+  {-# INLINE putF  #-}   {-# INLINE lensF #-}  - ---------------------------------------------------------------- -- Cont. vectors and their instances ----------------------------------------------------------------@@ -787,20 +855,27 @@  -- | /O(1)/ Prepend element to vector cons :: a -> ContVec n a -> ContVec (S n) a-cons a (ContVec cont) = ContVec $ \f -> cont $ apFun f a+cons a (ContVec cont) = ContVec $ \f -> cont $ curryFirst f a {-# INLINE cons #-} --- | Prepend single element to vector.+-- | Prepend single element vector to another vector. consV :: forall n a. ContVec (S Z) a -> ContVec n a -> ContVec (S n) a {-# INLINE consV #-} consV (ContVec cont1) (ContVec cont)-  = ContVec $ \f -> cont $ apFun f $ cont1 $ Fun id-+  = ContVec $ \f -> cont $ curryFirst f $ cont1 $ Fun id  -- | /O(1)/ Append element to vector snoc :: Arity n => a -> ContVec n a -> ContVec (S n) a snoc a (ContVec cont) = ContVec $ \f -> cont $ apLast f a {-# INLINE snoc #-}++-- | Concatenate vector+concat :: (Arity n, Arity k, Arity (Add n k))+       => ContVec n a -> ContVec k a -> ContVec (Add n k) a+{-# INLINE concat #-}+concat v u = inspect u+           $ inspect v+           $ curryMany construct  -- | Reverse order of elements in the vector reverse :: Arity n => ContVec n a -> ContVec n a
Data/Vector/Fixed/Internal.hs view
@@ -1,3 +1,4 @@+{-# LANGUAGE TypeOperators         #-} {-# LANGUAGE FlexibleContexts      #-} {-# LANGUAGE FlexibleInstances     #-} {-# LANGUAGE MultiParamTypeClasses #-}@@ -14,12 +15,12 @@ import qualified Data.Traversable as T  -import Data.Vector.Fixed.Cont     (Vector(..),Dim,S,Z,Arity,vector)+import Data.Vector.Fixed.Cont     (Vector(..),Dim,S,Z,Arity,vector,Add) import qualified Data.Vector.Fixed.Cont as C import           Data.Vector.Fixed.Cont   (ContVec,Index) import Prelude hiding ( replicate,map,zipWith,maximum,minimum,and,or,all,any                       , foldl,foldr,foldl1,length,sum,reverse,scanl,scanl1-                      , head,tail,mapM,mapM_,sequence,sequence_+                      , head,tail,mapM,mapM_,sequence,sequence_,concat                       )  @@ -213,6 +214,11 @@ {-# INLINE snoc #-} snoc a = vector . C.snoc a . C.cvec +concat :: (Vector v a, Vector u a, Vector w a, (Add (Dim v) (Dim u)) ~ Dim w)+       => v a -> u a -> w a+{-# INLINE concat #-}+concat v u = vector $ C.concat (C.cvec v) (C.cvec u)+ -- | Reverse order of elements in the vector reverse :: Vector v a => v a -> v a reverse = vector . C.reverse . C.cvec@@ -234,6 +240,12 @@ {-# INLINE index #-} index v k = C.runContVec (C.getF k)           $ C.cvec v  ++-- | Set n'th element in the vector+set :: (Vector v a, C.Index k (Dim v)) => k -> a -> v a -> v a+{-# INLINE set #-}+set k a v = inspect v+          $ C.putF k a construct   -- | Twan van Laarhoven's lens for element of vector element :: (Vector v a, Functor f) => Int -> (a -> f a) -> (v a -> f (v a))
fixed-vector.cabal view
@@ -1,5 +1,5 @@ Name:           fixed-vector-Version:        0.6.4.0+Version:        0.7.0.0 Synopsis:       Generic vectors with statically known size. Description:   Generic library for vectors with statically known