packages feed

fixed-vector 0.6.0.0 → 0.6.1.0

raw patch · 5 files changed

+80/−4 lines, 5 files

Files

ChangeLog view
@@ -1,3 +1,8 @@+Changes in 0.6.1.0++  * `distribute', `collect' and their monadic variants added.++ Changes in 0.6.0.0    * Data instance for all array-based vectors added.
Data/Vector/Fixed.hs view
@@ -103,6 +103,10 @@   , sequence_   , sequenceA   , traverse+  , distribute+  , collect+  , distributeM+  , collectM     -- * Folding   , foldl   , foldr
Data/Vector/Fixed/Cont.hs view
@@ -72,6 +72,10 @@   , imapM_   , sequence   , sequence_+  , distribute+  , collect+  , distributeM+  , collectM   , tail   , reverse     -- ** Zips@@ -110,6 +114,7 @@   ) where  import Control.Applicative (Applicative(..),(<$>))+import Control.Monad       (liftM) import Data.Complex        (Complex(..)) import Data.Data           (Typeable(..),Data) import qualified Data.Foldable    as F@@ -237,9 +242,9 @@  -- | Apply all parameters to the function using monadic actions. applyM :: (Monad m, Arity n)-         => (forall k. t (S k) -> m (a, t k)) -- ^ Get value to apply to function-         -> t n                               -- ^ Initial value-         -> m (ContVec n a)+       => (forall k. t (S k) -> m (a, t k)) -- ^ Get value to apply to function+       -> t n                               -- ^ Initial value+       -> m (ContVec n a) {-# INLINE applyM #-} applyM f t = do (v,_) <- applyFunM f t                 return v@@ -655,6 +660,45 @@ sequence_ = mapM_ id {-# INLINE sequence_ #-} +-- | The dual of sequenceA+distribute :: forall f n a. (Functor f, Arity n)+           => f (ContVec n a) -> ContVec n (f a)+{-# INLINE distribute #-}+distribute f0+  =  ContVec $ \(Fun fun) -> apply step start fun+  where+    -- It's not possible to use ContVec as accumulator type since `head'+    -- require Arity constraint on `k'. So we use plain lists+    step :: forall k. T_distribute a f (S k) -> (f a, T_distribute a f k)+    step (T_distribute f) = ( fmap (\(x:_) -> x) f+                            , T_distribute $ fmap (\(_:x) -> x) f)+    start :: T_distribute a f n+    start = T_distribute (fmap toList f0)++collect :: (Functor f, Arity n) => (a -> ContVec n b) -> f a -> ContVec n (f b)+collect f = distribute . fmap f+{-# INLINE collect #-}++-- | The dual of sequence+distributeM :: forall m n a. (Monad m, Arity n)+            => m (ContVec n a) -> ContVec n (m a)+{-# INLINE distributeM #-}+distributeM f0+  =  ContVec $ \(Fun fun) -> apply step start fun+  where+    step :: forall k. T_distribute a m (S k) -> (m a, T_distribute a m k)+    step (T_distribute f) = ( liftM (\(x:_) -> x) f+                            , T_distribute $ liftM (\(_:x) -> x) f)+    start :: T_distribute a m n+    start = T_distribute (liftM toList f0)++collectM :: (Monad m, Arity n) => (a -> ContVec n b) -> m a -> ContVec n (m b)+collectM f = distributeM . liftM f+{-# INLINE collectM #-}++newtype T_distribute a f n = T_distribute (f [a])++ -- | /O(1)/ Tail of vector. tail :: ContVec (S n) a -> ContVec n a tail (ContVec cont) = ContVec $ \f -> cont $ constFun f@@ -756,6 +800,9 @@  -- | Finalizer function for getting head of the vector. head :: forall n a. Arity (S n) => ContVec (S n) a -> a+-- NOTE: we need constraint `Arity (S n)' instead of `Arity n' because+--       `Vector v' entails `Arity (Dim v)' and GHC cannot figure out+--       that `Arity (S n)' ⇒ `Arity n' {-# INLINE head #-} head   = runContVec $ Fun
Data/Vector/Fixed/Internal.hs view
@@ -456,6 +456,26 @@ {-# INLINE traverse #-} traverse f = fmap vector . T.traverse f . C.cvec +distribute :: (Vector v a, Vector v (f a), Functor f)+           => f (v a) -> v (f a)+{-# INLINE distribute #-}+distribute = vector . C.distribute . fmap C.cvec++collect :: (Vector v a, Vector v b, Vector v (f b), Functor f)+        => (a -> v b) -> f a -> v (f b)+{-# INLINE collect #-}+collect f = vector . C.collect (C.cvec . f)++distributeM :: (Vector v a, Vector v (m a), Monad m)+           => m (v a) -> v (m a)+{-# INLINE distributeM #-}+distributeM = vector . C.distributeM . liftM C.cvec++collectM :: (Vector v a, Vector v b, Vector v (m b), Monad m)+         => (a -> v b) -> m a -> v (m b)+{-# INLINE collectM #-}+collectM f = vector . C.collectM (C.cvec . f)+   ----------------------------------------------------------------
fixed-vector.cabal view
@@ -1,5 +1,5 @@ Name:           fixed-vector-Version:        0.6.0.0+Version:        0.6.1.0 Synopsis:       Generic vectors with statically known size. Description:   Generic library for vectors with statically known