-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Generic vectors with fixed length -- -- Generic vectors with fixed length. Package is structured as follows: -- --
-- forall n. (Arity n, Vector (v n) a, Dim (v n) ~ n) => VectorN v a ---- -- Alas polymorphic constraints aren't allowed in haskell. class (Vector (v n) a, Dim (v n) ~ n) => VectorN v n a -- | Length of vector. Function doesn't evaluate its argument. length :: Arity (Dim v) => v a -> Int -- | Strict identity monad newtype Id a Id :: a -> Id a runID :: Id a -> a instance (b ~ a, c ~ a, d ~ a, e ~ a) => Vector ((,,,,) b c d e) a instance (b ~ a, c ~ a, d ~ a) => Vector ((,,,) b c d) a instance (b ~ a, c ~ a) => Vector ((,,) b c) a instance b ~ a => Vector ((,) b) a instance RealFloat a => Vector Complex a instance Monad Id instance Arity n => Arity (S n) instance Arity Z instance Arity n => Functor (Fun n a) -- | Continuations-based API module Data.Vector.Fixed.Cont -- | Vector represented as continuation. data ContVecT m n a -- | Vector as continuation without monadic context. type ContVec = ContVecT Id type N1 = S Z type N2 = S N1 type N3 = S N2 type N4 = S N3 type N5 = S N4 type N6 = S N5 -- | Convert regular vector to continuation cvec :: (Vector v a, Dim v ~ n, Monad m) => v a -> ContVecT m n a -- | Convert list to continuation-based vector. Will throw error if list is -- shorter than resulting vector. fromList :: Arity n => [a] -> ContVecT m n a -- | Execute monadic action for every element of vector. Synonym for -- pure. replicate :: Arity n => a -> ContVecT m n a -- | Execute monadic action for every element of vector. replicateM :: (Arity n, Monad m) => m a -> ContVecT m n a -- | Generate vector from function which maps element's index to its value. generate :: Arity n => (Int -> a) -> ContVecT m n a -- | Generate vector from monadic function which maps element's index to -- its value. generateM :: (Monad m, Arity n) => (Int -> m a) -> ContVecT m n a -- | Unit vector along Nth axis. basis :: (Num a, Arity n) => Int -> ContVecT m n a mk1 :: a -> ContVecT m N1 a mk2 :: a -> a -> ContVecT m N2 a mk3 :: a -> a -> a -> ContVecT m N3 a mk4 :: a -> a -> a -> a -> ContVecT m N4 a mk5 :: a -> a -> a -> a -> a -> ContVecT m N5 a -- | Map over vector. Synonym for fmap map :: Arity n => (a -> b) -> ContVecT m n a -> ContVecT m n b -- | Apply function to every element of the vector and its index. imap :: Arity n => (Int -> a -> b) -> ContVecT m n a -> ContVecT m n b -- | Monadic map over vector. mapM :: (Arity n, Monad m) => (a -> m b) -> ContVecT m n a -> ContVecT m n b -- | Apply monadic function to every element of the vector and its index. imapM :: (Arity n, Monad m) => (Int -> a -> m b) -> ContVecT m n a -> ContVecT m n b -- | O(1) Tail of vector. tail :: ContVecT m (S n) a -> ContVecT m n a -- | O(1) Prepend element to vector cons :: a -> ContVecT m n a -> ContVecT m (S n) a -- | Zip two vector together using function. zipWith :: Arity n => (a -> b -> c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n c -- | Zip two vector together using function which takes element index as -- well. izipWith :: Arity n => (Int -> a -> b -> c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n c -- | Zip two vector together using monadic function. zipWithM :: (Arity n, Monad m) => (a -> b -> m c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n c -- | Zip two vector together using monadic function which takes element -- index as well.. izipWithM :: (Arity n, Monad m) => (Int -> a -> b -> m c) -> ContVecT m n a -> ContVecT m n b -> ContVecT m n c -- | Run continuation vector using non-monadic finalizer. runContVecT :: (Monad m, Arity n) => Fun n a r -> ContVecT m n a -> m r -- | Run continuation vector using monadic finalizer. runContVecM :: Arity n => Fun n a (m r) -> ContVecT m n a -> m r -- | Run continuation vector. runContVec :: Arity n => Fun n a r -> ContVec n a -> r -- | Finalizer function for getting head of the vector. head :: Arity (S n) => Fun (S n) a a -- | Convert continuation to the vector. vector :: (Vector v a, Dim v ~ n) => ContVec n a -> v a -- | Convert continuation to the vector. vectorM :: (Vector v a, Dim v ~ n, Monad m) => ContVecT m n a -> m (v a) -- | Left fold over continuation vector. foldl :: Arity n => (b -> a -> b) -> b -> Fun n a b -- | Left fold. foldl1 :: Arity (S n) => (a -> a -> a) -> Fun (S n) a a -- | Right fold over continuation vector foldr :: Arity n => (a -> b -> b) -> b -> Fun n a b -- | Left fold over continuation vector. ifoldl :: Arity n => (b -> Int -> a -> b) -> b -> Fun n a b -- | Right fold over continuation vector ifoldr :: Arity n => (Int -> a -> b -> b) -> b -> Fun n a b -- | Monadic left fold over continuation vector. foldM :: (Arity n, Monad m) => (b -> a -> m b) -> b -> Fun n a (m b) -- | Monadic left fold over continuation vector. ifoldM :: (Arity n, Monad m) => (b -> Int -> a -> m b) -> b -> Fun n a (m b) -- | Sum all elements in the vector. sum :: (Num a, Arity n) => Fun n a a -- | Minimal element of vector. minimum :: (Ord a, Arity (S n)) => Fun (S n) a a -- | Maximal element of vector. maximum :: (Ord a, Arity (S n)) => Fun (S n) a a -- | Conjunction of elements of a vector. and :: Arity n => Fun n Bool Bool -- | Disjunction of all elements of a vector. or :: Arity n => Fun n Bool Bool -- | Determines whether all elements of vector satisfy predicate. all :: Arity n => (a -> Bool) -> Fun n a Bool -- | Determines whether any of element of vector satisfy predicate. any :: Arity n => (a -> Bool) -> Fun n a Bool -- | Vector based on the lists. Not very useful by itself but is necessary -- for implementation. data VecList n a instance Show a => Show (VecList n a) instance Eq a => Eq (VecList n a) instance Arity n => VectorN VecList n a instance Arity n => Vector (VecList n) a instance Arity n => Applicative (ContVecT m n) instance Arity n => Functor (ContVecT m n) -- | Type classes for array based vector. They are quite similar to ones -- from vector package but those only suitable for vectors with -- variable length. module Data.Vector.Fixed.Mutable -- | Mutable counterpart of fixed-length vector -- | Dimension for mutable vector -- | Type class for mutable vectors class Arity (DimM v) => MVector v a overlaps :: MVector v a => v s a -> v s a -> Bool copy :: (MVector v a, PrimMonad m) => v (PrimState m) a -> v (PrimState m) a -> m () move :: (MVector v a, PrimMonad m) => v (PrimState m) a -> v (PrimState m) a -> m () new :: (MVector v a, PrimMonad m) => m (v (PrimState m) a) unsafeRead :: (MVector v a, PrimMonad m) => v (PrimState m) a -> Int -> m a unsafeWrite :: (MVector v a, PrimMonad m) => v (PrimState m) a -> Int -> a -> m () -- | Length of mutable vector lengthM :: Arity (DimM v) => v s a -> Int -- | Read value at index with bound checks. read :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> m a -- | Write value at index with bound checks. write :: (PrimMonad m, MVector v a) => v (PrimState m) a -> Int -> a -> m () -- | Clone vector clone :: (PrimMonad m, MVector v a) => v (PrimState m) a -> m (v (PrimState m) a) -- | Type class for immutable vectors class (Dim v ~ DimM (Mutable v), MVector (Mutable v) a) => IVector v a unsafeFreeze :: (IVector v a, PrimMonad m) => Mutable v (PrimState m) a -> m (v a) unsafeThaw :: (IVector v a, PrimMonad m) => v a -> m (Mutable v (PrimState m) a) unsafeIndex :: IVector v a => v a -> Int -> a index :: IVector v a => v a -> Int -> a -- | Length of immutable vector lengthI :: IVector v a => v a -> Int -- | Safely convert mutable vector to immutable. freeze :: (PrimMonad m, IVector v a) => Mutable v (PrimState m) a -> m (v a) -- | Safely convert immutable vector to mutable. thaw :: (PrimMonad m, IVector v a) => v a -> m (Mutable v (PrimState m) a) -- | Generic construct constructVec :: (Arity (Dim v), IVector v a) => Fun (Dim v) a (v a) -- | Generic inspect inspectVec :: (Arity (Dim v), IVector v a) => v a -> Fun (Dim v) a b -> b -- | Generic API for vectors with fixed length. -- -- For encoding of vector size library uses Peano naturals defined in the -- library. At come point in the future it would make sense to switch to -- new GHC type level numerals. module Data.Vector.Fixed -- | Size of vector expressed as type-level natural. -- | Type level zero data Z -- | Successor of n data S n type N1 = S Z type N2 = S N1 type N3 = S N2 type N4 = S N3 type N5 = S N4 type N6 = S N5 -- | Type class for vectors with fixed length. class Arity (Dim v) => Vector v a construct :: Vector v a => Fun (Dim v) a (v a) inspect :: Vector v a => v a -> Fun (Dim v) a b -> b -- | Vector parametrized by length. In ideal world it should be: -- --
-- forall n. (Arity n, Vector (v n) a, Dim (v n) ~ n) => VectorN v a ---- -- Alas polymorphic constraints aren't allowed in haskell. class (Vector (v n) a, Dim (v n) ~ n) => VectorN v n a -- | Type class for handling n-ary functions. class Arity n -- | Newtype wrapper which is used to make Fn injective. newtype Fun n a b Fun :: (Fn n a b) -> Fun n a b -- | Length of vector. Function doesn't evaluate its argument. length :: Arity (Dim v) => v a -> Int mk1 :: (Vector v a, Dim v ~ N1) => a -> v a mk2 :: (Vector v a, Dim v ~ N2) => a -> a -> v a mk3 :: (Vector v a, Dim v ~ N3) => a -> a -> a -> v a mk4 :: (Vector v a, Dim v ~ N4) => a -> a -> a -> a -> v a mk5 :: (Vector v a, Dim v ~ N5) => a -> a -> a -> a -> a -> v a -- | Generic function for construction of arbitrary vectors. It represents -- partially constructed vector where n is number of uninitialized -- elements, v is type of vector and a element type. -- -- Uninitialized vector could be obtained from con and vector -- elements could be added from left to right using |> -- operator. Finally it could be converted to vector using vec -- function. -- -- Construction of complex number which could be seen as 2-element -- vector: -- --
-- >>> import Data.Complex -- -- >>> vec $ con |> 1 |> 3 :: Complex Double -- 1.0 :+ 3.0 --data New n v a -- | Convert fully applied constructor to vector vec :: New Z v a -> v a -- | Seed constructor con :: Vector v a => New (Dim v) v a -- | Apply another element to vector (|>) :: New (S n) v a -> a -> New n v a -- | Replicate value n times. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec2) -- -- >>> replicate 1 :: Vec2 Int -- fromList [1,1] ---- --
-- >>> replicate 2 :: (Double,Double,Double) -- (2.0,2.0,2.0) ---- --
-- >>> import Data.Vector.Fixed.Boxed (Vec) -- -- >>> replicate "foo" :: Vec N5 String -- fromList ["foo","foo","foo","foo","foo"] --replicate :: Vector v a => a -> v a -- | Execute monadic action for every element of vector. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec2,Vec3) -- -- >>> replicateM (Just 3) :: Maybe (Vec3 Int) -- Just fromList [3,3,3] -- -- >>> replicateM (putStrLn "Hi!") :: IO (Vec2 ()) -- Hi! -- Hi! -- fromList [(),()] --replicateM :: (Vector v a, Monad m) => m a -> m (v a) -- | Unit vector along Nth axis. If index is larger than vector dimensions -- returns zero vector. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec3) -- -- >>> basis 0 :: Vec3 Int -- fromList [1,0,0] -- -- >>> basis 1 :: Vec3 Int -- fromList [0,1,0] -- -- >>> basis 3 :: Vec3 Int -- fromList [0,0,0] --basis :: (Vector v a, Num a) => Int -> v a -- | Generate vector from function which maps element's index to its value. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Unboxed (Vec) -- -- >>> generate (^2) :: Vec N4 Int -- fromList [0,1,4,9] --generate :: Vector v a => (Int -> a) -> v a -- | Generate vector from monadic function which maps element's index to -- its value. generateM :: (Monad m, Vector v a) => (Int -> m a) -> m (v a) -- | First element of vector. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec3) -- -- >>> let x = mk3 1 2 3 :: Vec3 Int -- -- >>> head x -- 1 --head :: (Vector v a, Dim v ~ S n) => v a -> a -- | Tail of vector. -- -- Examples: -- --
-- >>> import Data.Complex -- -- >>> tail (1,2,3) :: Complex Double -- 2.0 :+ 3.0 --tail :: (Vector v a, Vector w a, Dim v ~ S (Dim w)) => v a -> w a -- | Test two vectors for equality. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec2) -- -- >>> let v0 = basis 0 :: Vec2 Int -- -- >>> let v1 = basis 1 :: Vec2 Int -- -- >>> v0 `eq` v0 -- True -- -- >>> v0 `eq` v1 -- False --eq :: (Vector v a, Eq a) => v a -> v a -> Bool -- | Map over vector map :: (Vector v a, Vector v b) => (a -> b) -> v a -> v b -- | Monadic map over vector. mapM :: (Vector v a, Vector v b, Monad m) => (a -> m b) -> v a -> m (v b) -- | Apply monadic action to each element of vector and ignore result. mapM_ :: (Vector v a, Monad m) => (a -> m b) -> v a -> m () -- | Apply function to every element of the vector and its index. imap :: (Vector v a, Vector v b) => (Int -> a -> b) -> v a -> v b -- | Apply monadic function to every element of the vector and its index. imapM :: (Vector v a, Vector v b, Monad m) => (Int -> a -> m b) -> v a -> m (v b) -- | Apply monadic function to every element of the vector and its index -- and discard result. imapM_ :: (Vector v a, Monad m) => (Int -> a -> m b) -> v a -> m () -- | Evaluate every action in the vector from left to right. sequence :: (Vector v a, Vector v (m a), Monad m) => v (m a) -> m (v a) -- | Evaluate every action in the vector from left to right and ignore -- result sequence_ :: (Vector v (m a), Monad m) => v (m a) -> m () -- | Left fold over vector foldl :: Vector v a => (b -> a -> b) -> b -> v a -> b -- | Left fold over vector foldr :: Vector v a => (a -> b -> b) -> b -> v a -> b -- | Left fold over vector foldl1 :: (Vector v a, Dim v ~ S n) => (a -> a -> a) -> v a -> a -- | Left fold over vector. Function is applied to each element and its -- index. ifoldl :: Vector v a => (b -> Int -> a -> b) -> b -> v a -> b -- | Left fold over vector ifoldr :: Vector v a => (Int -> a -> b -> b) -> b -> v a -> b -- | Monadic fold over vector. foldM :: (Vector v a, Monad m) => (b -> a -> m b) -> b -> v a -> m b -- | Left monadic fold over vector. Function is applied to each element and -- its index. ifoldM :: (Vector v a, Monad m) => (b -> Int -> a -> m b) -> b -> v a -> m b -- | Sum all elements in the vector. sum :: (Vector v a, Num a) => v a -> a -- | Maximal element of vector. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec3) -- -- >>> let x = mk3 1 2 3 :: Vec3 Int -- -- >>> maximum x -- 3 --maximum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a -- | Minimal element of vector. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec3) -- -- >>> let x = mk3 1 2 3 :: Vec3 Int -- -- >>> minimum x -- 1 --minimum :: (Vector v a, Dim v ~ S n, Ord a) => v a -> a -- | Conjunction of all elements of a vector. and :: Vector v Bool => v Bool -> Bool -- | Disjunction of all elements of a vector. or :: Vector v Bool => v Bool -> Bool -- | Determines whether all elements of vector satisfy predicate. all :: Vector v a => (a -> Bool) -> v a -> Bool -- | Determines whether any of element of vector satisfy predicate. any :: Vector v a => (a -> Bool) -> v a -> Bool -- | Zip two vector together using function. -- -- Examples: -- --
-- >>> import Data.Vector.Fixed.Boxed (Vec3) -- -- >>> let b0 = basis 0 :: Vec3 Int -- -- >>> let b1 = basis 1 :: Vec3 Int -- -- >>> let b2 = basis 2 :: Vec3 Int -- -- >>> let vplus x y = zipWith (+) x y -- -- >>> vplus b0 b1 -- fromList [1,1,0] -- -- >>> vplus b0 b2 -- fromList [1,0,1] -- -- >>> vplus b1 b2 -- fromList [0,1,1] --zipWith :: (Vector v a, Vector v b, Vector v c) => (a -> b -> c) -> v a -> v b -> v c -- | Zip two vector together using monadic function. zipWithM :: (Vector v a, Vector v b, Vector v c, Monad m) => (a -> b -> m c) -> v a -> v b -> m (v c) -- | Zip two vector together using function which takes element index as -- well. izipWith :: (Vector v a, Vector v b, Vector v c) => (Int -> a -> b -> c) -> v a -> v b -> v c -- | Zip two vector together using monadic function which takes element -- index as well.. izipWithM :: (Vector v a, Vector v b, Vector v c, Monad m) => (Int -> a -> b -> m c) -> v a -> v b -> m (v c) -- | Convert between different vector types convert :: (Vector v a, Vector w a, Dim v ~ Dim w) => v a -> w a -- | Convert vector to the list toList :: Vector v a => v a -> [a] -- | Create vector form list. Will throw error if list is shorter than -- resulting vector. fromList :: Vector v a => [a] -> v a -- | Vector based on the lists. Not very useful by itself but is necessary -- for implementation. data VecList n a -- | Boxed vector. module Data.Vector.Fixed.Boxed -- | Vector with fixed length which can hold any value. data Vec n a type Vec2 = Vec (S (S Z)) type Vec3 = Vec (S (S (S Z))) -- | Mutable unboxed vector with fixed length data MVec n s a instance (Arity n, Eq a) => Eq (Vec n a) instance Arity n => VectorN Vec n a instance Arity n => Vector (Vec n) a instance Arity n => IVector (Vec n) a instance Arity n => MVector (MVec n) a instance (Arity n, Show a) => Show (Vec n a) -- | Unboxed vectors with fixed length. Vectors from -- Data.Vector.Fixed.Unboxed provide more flexibility at no -- performeance cost. module Data.Vector.Fixed.Primitive -- | Unboxed vector with fixed length data Vec n a type Vec2 = Vec (S (S Z)) type Vec3 = Vec (S (S (S Z))) -- | Mutable unboxed vector with fixed length data MVec n s a instance (Arity n, Prim a, Eq a) => Eq (Vec n a) instance (Arity n, Prim a) => VectorN Vec n a instance (Arity n, Prim a) => Vector (Vec n) a instance (Arity n, Prim a) => IVector (Vec n) a instance (Arity n, Prim a) => MVector (MVec n) a instance (Arity n, Prim a, Show a) => Show (Vec n a) -- | Unboxed vectors with fixed length. module Data.Vector.Fixed.Unboxed type Vec2 = Vec (S (S Z)) type Vec3 = Vec (S (S (S Z))) class (IVector (Vec n) a, MVector (MVec n) a) => Unbox n a instance (Arity n, Vector (Vec n) a, Vector (Vec n) b, Vector (Vec n) c, IVector (Vec n) a, IVector (Vec n) b, IVector (Vec n) c) => IVector (Vec n) (a, b, c) instance (Arity n, MVector (MVec n) a, MVector (MVec n) b, MVector (MVec n) c) => MVector (MVec n) (a, b, c) instance (Unbox n a, Unbox n b, Unbox n c) => Unbox n (a, b, c) instance (Arity n, IVector (Vec n) a, IVector (Vec n) b) => IVector (Vec n) (a, b) instance (Arity n, MVector (MVec n) a, MVector (MVec n) b) => MVector (MVec n) (a, b) instance (Unbox n a, Unbox n b) => Unbox n (a, b) instance (Arity n, IVector (Vec n) a) => IVector (Vec n) (Complex a) instance (Arity n, MVector (MVec n) a) => MVector (MVec n) (Complex a) instance Unbox n a => Unbox n (Complex a) instance Arity n => IVector (Vec n) Double instance Arity n => MVector (MVec n) Double instance Arity n => Unbox n Double instance Arity n => IVector (Vec n) Float instance Arity n => MVector (MVec n) Float instance Arity n => Unbox n Float instance Arity n => IVector (Vec n) Char instance Arity n => MVector (MVec n) Char instance Arity n => Unbox n Char instance Arity n => IVector (Vec n) Word64 instance Arity n => MVector (MVec n) Word64 instance Arity n => Unbox n Word64 instance Arity n => IVector (Vec n) Word32 instance Arity n => MVector (MVec n) Word32 instance Arity n => Unbox n Word32 instance Arity n => IVector (Vec n) Word16 instance Arity n => MVector (MVec n) Word16 instance Arity n => Unbox n Word16 instance Arity n => IVector (Vec n) Word8 instance Arity n => MVector (MVec n) Word8 instance Arity n => Unbox n Word8 instance Arity n => IVector (Vec n) Word instance Arity n => MVector (MVec n) Word instance Arity n => Unbox n Word instance Arity n => IVector (Vec n) Int64 instance Arity n => MVector (MVec n) Int64 instance Arity n => Unbox n Int64 instance Arity n => IVector (Vec n) Int32 instance Arity n => MVector (MVec n) Int32 instance Arity n => Unbox n Int32 instance Arity n => IVector (Vec n) Int16 instance Arity n => MVector (MVec n) Int16 instance Arity n => Unbox n Int16 instance Arity n => IVector (Vec n) Int8 instance Arity n => MVector (MVec n) Int8 instance Arity n => Unbox n Int8 instance Arity n => IVector (Vec n) Int instance Arity n => MVector (MVec n) Int instance Arity n => Unbox n Int instance Arity n => IVector (Vec n) Bool instance Arity n => MVector (MVec n) Bool instance Arity n => Unbox n Bool instance Arity n => IVector (Vec n) () instance Arity n => MVector (MVec n) () instance Arity n => Unbox n () instance (Unbox n a, Eq a) => Eq (Vec n a) instance Unbox n a => VectorN Vec n a instance Unbox n a => Vector (Vec n) a instance (Arity n, Show a, Unbox n a) => Show (Vec n a) -- | Storable-based unboxed vectors. module Data.Vector.Fixed.Storable -- | Storable-based vector with fixed length data Vec n a type Vec2 = Vec (S (S Z)) type Vec3 = Vec (S (S (S Z))) -- | Construct vector from foreign pointer. unsafeFromForeignPtr :: Storable a => ForeignPtr a -> Vec n a -- | Get underlying pointer. Data may not be modified through pointer. unsafeToForeignPtr :: Storable a => Vec n a -> ForeignPtr a unsafeWith :: Storable a => (Ptr a -> IO b) -> Vec n a -> IO b -- | Storable-based mutable vector with fixed length newtype MVec n s a MVec :: (ForeignPtr a) -> MVec n s a instance (Arity n, Storable a, Eq a) => Eq (Vec n a) instance (Arity n, Storable a) => VectorN Vec n a instance (Arity n, Storable a) => Vector (Vec n) a instance (Arity n, Storable a) => IVector (Vec n) a instance (Arity n, Storable a) => MVector (MVec n) a instance (Arity n, Storable a, Show a) => Show (Vec n a)