packages feed

fixed-vector 0.4.3.0 → 0.4.4.0

raw patch · 4 files changed

+55/−3 lines, 4 filesPVP ok

version bump matches the API change (PVP)

API changes (from Hackage documentation)

+ Data.Vector.Fixed.Cont: instance Arity n => Index Z (S n)
+ Data.Vector.Fixed.Cont: instance Index k n => Index (S k) (S n)
+ Data.Vector.Fixed.Internal.Arity: instance Arity n => Applicative (Fun n a)
+ Data.Vector.Fixed.Internal.Id: instance Applicative Id
+ Data.Vector.Fixed.Internal.Id: instance Functor Id

Files

Data/Vector/Fixed/Cont.hs view
@@ -127,8 +127,22 @@ {-# INLINE length #-} length _ = arity (undefined :: Dim v) +-- | Type class for indexing of vector when index value is known at+--   compile time.+class Index k n where+  getF :: k -> Fun n a a+  putF :: k -> a -> Fun n a a -> Fun n a a +instance Arity n => Index Z (S n) where+  getF _           = Fun $ \(a :: a) -> unFun (pure a :: Fun n a a)+  putF _ x (Fun f) = Fun $ \_ -> f x +instance Index k n => Index (S k) (S n) where+  getF _           = Fun $ \(_::a) -> unFun (getF (undefined :: k) :: Fun n a a)+  putF _ x (Fun f) = Fun $ \(a::a) -> unFun $ putF (undefined :: k) x (Fun (f a) :: Fun n a a)+++ ---------------------------------------------------------------- -- Cont. vectors and their instances ----------------------------------------------------------------@@ -209,6 +223,7 @@ -- | Convert list to continuation-based vector. Will fail with --   'Nothing' if list doesn't have right length. fromListM :: forall n a. Arity n => [a] -> ContVecT Maybe n a+{-# INLINE fromListM #-} fromListM xs = ContVecT $ \(Fun fun) -> do   (r,rest) <- applyFunM step (T_flist xs :: T_flist a n) fun   case rest of
Data/Vector/Fixed/Internal/Arity.hs view
@@ -24,7 +24,8 @@   , applyM   ) where -import Data.Typeable (Typeable)+import Control.Applicative (Applicative(..))+import Data.Typeable       (Typeable)   @@ -58,7 +59,6 @@ -- | Newtype wrapper which is used to make 'Fn' injective. newtype Fun n a b = Fun { unFun :: Fn n a b } -newtype T_fmap a b n = T_fmap (Fn n a b)  instance Arity n => Functor (Fun n a) where   fmap (f :: b -> c) (Fun g0 :: Fun n a b)@@ -68,6 +68,26 @@              (T_fmap g0 :: T_fmap a b n)   {-# INLINE fmap #-} +instance Arity n => Applicative (Fun n a) where+  pure (x :: x) = Fun $ accum (\(T_pure r) (_::a) -> T_pure r)+                              (\(T_pure r)        -> r)+                              (T_pure x :: T_pure x n)+  (Fun f0 :: Fun n a (p -> q)) <*> (Fun g0 :: Fun n a p)+    = Fun $ accum (\(T_ap f g) a -> T_ap (f a) (g a))+                  (\(T_ap f g)   -> f g)+                  (T_ap f0 g0 :: T_ap a (p -> q) p n)+  {-# INLINE pure  #-}+  {-# INLINE (<*>) #-}++newtype T_fmap a b   n = T_fmap (Fn n a b)+data    T_pure a     n = T_pure a+data    T_ap   a b c n = T_ap (Fn n a b) (Fn n a c)++++----------------------------------------------------------------+-- Generic operations of N-ary functions+----------------------------------------------------------------  -- | Type class for handling /n/-ary functions. class Arity n where
Data/Vector/Fixed/Internal/Id.hs view
@@ -4,8 +4,21 @@     Id(..)   ) where +import Control.Applicative (Applicative(..))++ -- | Strict identity monad newtype Id a = Id { runID :: a }++instance Functor Id where+  fmap f (Id a) = Id (f a)+  {-# INLINE fmap #-}++instance Applicative Id where+  pure          = Id+  Id f <*> Id a = Id (f a)+  {-# INLINE pure  #-}+  {-# INLINE (<*>) #-}  instance Monad Id where   return     = Id
fixed-vector.cabal view
@@ -1,5 +1,5 @@ Name:           fixed-vector-Version:        0.4.3.0+Version:        0.4.4.0 Synopsis:       Generic vectors with statically known size. Description:   Generic library for vectors with statically known@@ -44,6 +44,10 @@   .   [@Data.Vector.Fixed.Monomorphic@]   Wrappers for monomorphic vectors+  .+  Changes in 0.4.4.0+  .+  * Functor and Applicative instances are added to Id.   .   Changes in 0.4.3.0   .