-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Efficient Arrays -- -- An efficient implementation of Int-indexed arrays with a powerful loop -- fusion framework. -- -- This code is highly experimental and for the most part untested. Use -- at your own risk! @package vector @version 0.2 -- | Primitives for manipulating unboxed arrays module Data.Vector.Unboxed.Unbox -- | Class of types which can be stored in unboxed arrays class Unbox a size# :: (Unbox a) => a -> Int# -> Int# at# :: (Unbox a) => ByteArray# -> Int# -> a read# :: (Unbox a) => MutableByteArray# s -> Int# -> State# s -> (# State# s, a #) write# :: (Unbox a) => MutableByteArray# s -> Int# -> a -> State# s -> State# s instance Unbox Double instance Unbox Float instance Unbox Int -- | Size hints module Data.Vector.Fusion.Stream.Size -- | Size hint data Size -- | Exact size Exact :: Int -> Size -- | Upper bound on the size Max :: Int -> Size -- | Unknown size Unknown :: Size -- | Minimum of two size hints smaller :: Size -> Size -> Size -- | Maximum of two size hints larger :: Size -> Size -> Size -- | Convert a size hint to an upper bound toMax :: Size -> Size -- | Compute the maximum size from a size hint if possible upperBound :: Size -> Maybe Int instance Eq Size instance Show Size instance Num Size -- | Monadic streams module Data.Vector.Fusion.Stream.Monadic -- | Monadic streams data Stream m a Stream :: (s -> m (Step s a)) -> s -> Size -> Stream m a -- | Result of taking a single step in a stream data Step s a -- | a new element and a new seed Yield :: a -> s -> Step s a -- | just a new seed Skip :: s -> Step s a -- | end of stream Done :: Step s a -- | Size hint of a Stream size :: Stream m a -> Size -- | Attach a Size hint to a Stream sized :: Stream m a -> Size -> Stream m a -- | Length of a Stream length :: (Monad m) => Stream m a -> m Int -- | Check if a Stream is empty null :: (Monad m) => Stream m a -> m Bool -- | Empty Stream empty :: (Monad m) => Stream m a -- | Singleton Stream singleton :: (Monad m) => a -> Stream m a -- | Prepend an element cons :: (Monad m) => a -> Stream m a -> Stream m a -- | Append an element snoc :: (Monad m) => Stream m a -> a -> Stream m a -- | Replicate a value to a given length replicate :: (Monad m) => Int -> a -> Stream m a -- | Concatenate two Streams (++) :: (Monad m) => Stream m a -> Stream m a -> Stream m a -- | First element of the Stream or error if empty head :: (Monad m) => Stream m a -> m a -- | Last element of the Stream or error if empty last :: (Monad m) => Stream m a -> m a -- | Element at the given position (!!) :: (Monad m) => Stream m a -> Int -> m a -- | Extract a substream of the given length starting at the given -- position. extract :: (Monad m) => Stream m a -> Int -> Int -> Stream m a -- | All but the last element init :: (Monad m) => Stream m a -> Stream m a -- | All but the first element tail :: (Monad m) => Stream m a -> Stream m a -- | The first n elements take :: (Monad m) => Int -> Stream m a -> Stream m a -- | All but the first n elements drop :: (Monad m) => Int -> Stream m a -> Stream m a -- | Map a function over a Stream map :: (Monad m) => (a -> b) -> Stream m a -> Stream m b -- | Map a monadic function over a Stream mapM :: (Monad m) => (a -> m b) -> Stream m a -> Stream m b -- | Execute a monadic action for each element of the Stream mapM_ :: (Monad m) => (a -> m b) -> Stream m a -> m () -- | Zip two Streams with the given function zipWith :: (Monad m) => (a -> b -> c) -> Stream m a -> Stream m b -> Stream m c -- | Zip two Streams with the given monadic function zipWithM :: (Monad m) => (a -> b -> m c) -> Stream m a -> Stream m b -> Stream m c -- | Drop elements which do not satisfy the predicate filter :: (Monad m) => (a -> Bool) -> Stream m a -> Stream m a -- | Drop elements which do not satisfy the monadic predicate filterM :: (Monad m) => (a -> m Bool) -> Stream m a -> Stream m a -- | Longest prefix of elements that satisfy the predicate takeWhile :: (Monad m) => (a -> Bool) -> Stream m a -> Stream m a -- | Longest prefix of elements that satisfy the monadic predicate takeWhileM :: (Monad m) => (a -> m Bool) -> Stream m a -> Stream m a -- | Drop the longest prefix of elements that satisfy the predicate dropWhile :: (Monad m) => (a -> Bool) -> Stream m a -> Stream m a -- | Drop the longest prefix of elements that satisfy the monadic predicate dropWhileM :: (Monad m) => (a -> m Bool) -> Stream m a -> Stream m a -- | Check whether the Stream contains an element elem :: (Monad m, Eq a) => a -> Stream m a -> m Bool -- | Inverse of elem notElem :: (Monad m, Eq a) => a -> Stream m a -> m Bool -- | Yield Just the first element that satisfies the predicate or -- Nothing if no such element exists. find :: (Monad m) => (a -> Bool) -> Stream m a -> m (Maybe a) -- | Yield Just the first element that satisfies the monadic -- predicate or Nothing if no such element exists. findM :: (Monad m) => (a -> m Bool) -> Stream m a -> m (Maybe a) -- | Yield Just the index of the first element that satisfies the -- predicate or Nothing if no such element exists. findIndex :: (Monad m) => (a -> Bool) -> Stream m a -> m (Maybe Int) -- | Yield Just the index of the first element that satisfies the -- monadic predicate or Nothing if no such element exists. findIndexM :: (Monad m) => (a -> m Bool) -> Stream m a -> m (Maybe Int) -- | Left fold foldl :: (Monad m) => (a -> b -> a) -> a -> Stream m b -> m a -- | Left fold with a monadic operator foldlM :: (Monad m) => (a -> b -> m a) -> a -> Stream m b -> m a -- | Same as foldlM foldM :: (Monad m) => (a -> b -> m a) -> a -> Stream m b -> m a -- | Left fold over a non-empty Stream foldl1 :: (Monad m) => (a -> a -> a) -> Stream m a -> m a -- | Left fold over a non-empty Stream with a monadic operator foldl1M :: (Monad m) => (a -> a -> m a) -> Stream m a -> m a -- | Left fold with a strict accumulator foldl' :: (Monad m) => (a -> b -> a) -> a -> Stream m b -> m a -- | Left fold with a strict accumulator and a monadic operator foldlM' :: (Monad m) => (a -> b -> m a) -> a -> Stream m b -> m a -- | Left fold over a non-empty Stream with a strict accumulator foldl1' :: (Monad m) => (a -> a -> a) -> Stream m a -> m a -- | Left fold over a non-empty Stream with a strict accumulator and -- a monadic operator foldl1M' :: (Monad m) => (a -> a -> m a) -> Stream m a -> m a -- | Right fold foldr :: (Monad m) => (a -> b -> b) -> b -> Stream m a -> m b -- | Right fold with a monadic operator foldrM :: (Monad m) => (a -> b -> m b) -> b -> Stream m a -> m b -- | Right fold over a non-empty stream foldr1 :: (Monad m) => (a -> a -> a) -> Stream m a -> m a -- | Right fold over a non-empty stream with a monadic operator foldr1M :: (Monad m) => (a -> a -> m a) -> Stream m a -> m a -- | Unfold unfold :: (Monad m) => (s -> Maybe (a, s)) -> s -> Stream m a -- | Unfold with a monadic function unfoldM :: (Monad m) => (s -> m (Maybe (a, s))) -> s -> Stream m a -- | Prefix scan prescanl :: (Monad m) => (a -> b -> a) -> a -> Stream m b -> Stream m a -- | Prefix scan with a monadic operator prescanlM :: (Monad m) => (a -> b -> m a) -> a -> Stream m b -> Stream m a -- | Prefix scan with strict accumulator prescanl' :: (Monad m) => (a -> b -> a) -> a -> Stream m b -> Stream m a -- | Prefix scan with strict accumulator and a monadic operator prescanlM' :: (Monad m) => (a -> b -> m a) -> a -> Stream m b -> Stream m a -- | Convert a Stream to a list toList :: (Monad m) => Stream m a -> m [a] -- | Convert a list to a Stream fromList :: (Monad m) => [a] -> Stream m a instance (Monad m) => Functor (Stream m) -- | Streams for stream fusion module Data.Vector.Fusion.Stream -- | Result of taking a single step in a stream data Step s a -- | a new element and a new seed Yield :: a -> s -> Step s a -- | just a new seed Skip :: s -> Step s a -- | end of stream Done :: Step s a -- | The type of pure streams type Stream = Stream Id -- | Alternative name for monadic streams type MStream = Stream -- | Identity monad newtype Id a Id :: a -> Id a unId :: Id a -> a -- | Size hint of a Stream size :: Stream a -> Size -- | Attach a Size hint to a Stream sized :: Stream a -> Size -> Stream a -- | Length of a Stream length :: Stream a -> Int -- | Check if a Stream is empty null :: Stream a -> Bool -- | Empty Stream empty :: Stream a -- | Singleton Stream singleton :: a -> Stream a -- | Prepend an element cons :: a -> Stream a -> Stream a -- | Append an element snoc :: Stream a -> a -> Stream a -- | Replicate a value to a given length replicate :: Int -> a -> Stream a -- | Concatenate two Streams (++) :: Stream a -> Stream a -> Stream a -- | First element of the Stream or error if empty head :: Stream a -> a -- | Last element of the Stream or error if empty last :: Stream a -> a -- | Element at the given position (!!) :: Stream a -> Int -> a -- | Extract a substream of the given length starting at the given -- position. extract :: Stream a -> Int -> Int -> Stream a -- | All but the last element init :: Stream a -> Stream a -- | All but the first element tail :: Stream a -> Stream a -- | The first n elements take :: Int -> Stream a -> Stream a -- | All but the first n elements drop :: Int -> Stream a -> Stream a -- | Map a function over a Stream map :: (a -> b) -> Stream a -> Stream b -- | Zip two Streams with the given function zipWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream c -- | Drop elements which do not satisfy the predicate filter :: (a -> Bool) -> Stream a -> Stream a -- | Longest prefix of elements that satisfy the predicate takeWhile :: (a -> Bool) -> Stream a -> Stream a -- | Drop the longest prefix of elements that satisfy the predicate dropWhile :: (a -> Bool) -> Stream a -> Stream a -- | Check whether the Stream contains an element elem :: (Eq a) => a -> Stream a -> Bool -- | Inverse of elem notElem :: (Eq a) => a -> Stream a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (a -> Bool) -> Stream a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (a -> Bool) -> Stream a -> Maybe Int -- | Left fold foldl :: (a -> b -> a) -> a -> Stream b -> a -- | Left fold on non-empty Streams foldl1 :: (a -> a -> a) -> Stream a -> a -- | Left fold with strict accumulator foldl' :: (a -> b -> a) -> a -> Stream b -> a -- | Left fold on non-empty Streams with strict accumulator foldl1' :: (a -> a -> a) -> Stream a -> a -- | Right fold foldr :: (a -> b -> b) -> b -> Stream a -> b -- | Right fold on non-empty Streams foldr1 :: (a -> a -> a) -> Stream a -> a -- | Unfold unfold :: (s -> Maybe (a, s)) -> s -> Stream a -- | Prefix scan prescanl :: (a -> b -> a) -> a -> Stream b -> Stream a -- | Prefix scan with strict accumulator prescanl' :: (a -> b -> a) -> a -> Stream b -> Stream a -- | Convert a Stream to a list toList :: Stream a -> [a] -- | Create a Stream from a list fromList :: [a] -> Stream a -- | Convert a pure stream to a monadic stream liftStream :: (Monad m) => Stream a -> Stream m a -- | Apply a monadic action to each element of the stream mapM_ :: (Monad m) => (a -> m ()) -> Stream a -> m () -- | Monadic fold foldM :: (Monad m) => (a -> b -> m a) -> a -> Stream b -> m a instance (Ord a) => Ord (Stream Id a) instance (Eq a) => Eq (Stream Id a) instance Monad Id instance Functor Id -- | Generic interface to mutable vectors module Data.Vector.MVector -- | Basic pure functions on mutable vectors class MVectorPure v a length :: (MVectorPure v a) => v a -> Int unsafeSlice :: (MVectorPure v a) => v a -> Int -> Int -> v a overlaps :: (MVectorPure v a) => v a -> v a -> Bool -- | Class of mutable vectors. The type m is the monad in which -- the mutable vector can be transformed and a is the type of -- elements. class (Monad m, MVectorPure v a) => MVector v m a unsafeNew :: (MVector v m a) => Int -> m (v a) unsafeNewWith :: (MVector v m a) => Int -> a -> m (v a) unsafeRead :: (MVector v m a) => v a -> Int -> m a unsafeWrite :: (MVector v m a) => v a -> Int -> a -> m () clear :: (MVector v m a) => v a -> m () set :: (MVector v m a) => v a -> a -> m () unsafeCopy :: (MVector v m a) => v a -> v a -> m () unsafeGrow :: (MVector v m a) => v a -> Int -> m (v a) -- | Yield a part of the mutable vector without copying it. Safer version -- of unsafeSlice. slice :: (MVectorPure v a) => v a -> Int -> Int -> v a -- | Create a mutable vector of the given length. Safer version of -- unsafeNew. new :: (MVector v m a) => Int -> m (v a) -- | Create a mutable vector of the given length and fill it with an -- initial value. Safer version of unsafeNewWith. newWith :: (MVector v m a) => Int -> a -> m (v a) -- | Yield the element at the given position. Safer version of -- unsafeRead. read :: (MVector v m a) => v a -> Int -> m a -- | Replace the element at the given position. Safer version of -- unsafeWrite. write :: (MVector v m a) => v a -> Int -> a -> m () -- | Copy a vector. The two vectors may not overlap. Safer version of -- unsafeCopy. copy :: (MVector v m a) => v a -> v a -> m () -- | Grow a vector by the given number of elements. Safer version of -- unsafeGrow. grow :: (MVector v m a) => v a -> Int -> m (v a) -- | Create a new mutable vector and fill it with elements from the -- Stream. The vector will grow logarithmically if the Size -- hint of the Stream is inexact. unstream :: (MVector v m a) => Stream a -> m (v a) transform :: (MVector v m a) => (MStream m a -> MStream m a) -> v a -> m (v a) update :: (MVector v m a) => v a -> Stream (Int, a) -> m () reverse :: (MVector v m a) => v a -> m () -- | Mutable unboxed vectors based on Unbox. module Data.Vector.Unboxed.Mutable -- | Mutable unboxed vectors. They live in the ST monad. data Vector s a Vector :: !!Int -> !!Int -> (MutableByteArray# s) -> Vector s a instance (Unbox a) => MVector (Vector s) (ST s) a instance (Unbox a) => MVectorPure (Vector s) a -- | Mutable boxed vectors. module Data.Vector.Mutable -- | Mutable boxed vectors. They live in the ST monad. data Vector s a Vector :: !!Int -> !!Int -> (MutableArray# s a) -> Vector s a instance MVector (Vector s) (ST s) a instance MVectorPure (Vector s) a module Data.Vector.MVector.New newtype New a New :: (forall m mv. (MVector mv m a) => m (mv a)) -> New a run :: (MVector mv m a) => New a -> m (mv a) unstream :: Stream a -> New a transform :: (forall m. (Monad m) => MStream m a -> MStream m a) -> New a -> New a update :: New a -> Stream (Int, a) -> New a reverse :: New a -> New a -- | Generic interface to pure vectors module Data.Vector.IVector -- | Class of immutable vectors. class IVector v a vnew :: (IVector v a) => (forall mv m. (MVector mv m a) => m (mv a)) -> v a vlength :: (IVector v a) => v a -> Int unsafeSlice :: (IVector v a) => v a -> Int -> Int -> v a unsafeIndex :: (IVector v a) => v a -> Int -> (a -> b) -> b length :: (IVector v a) => v a -> Int -- | Empty vector empty :: (IVector v a) => v a -- | Vector with exaclty one element singleton :: (IVector v a) => a -> v a -- | Prepend an element cons :: (IVector v a) => a -> v a -> v a -- | Append an element snoc :: (IVector v a) => v a -> a -> v a -- | Vector of the given length with the given value in each position replicate :: (IVector v a) => Int -> a -> v a -- | Concatenate two vectors (++) :: (IVector v a) => v a -> v a -> v a -- | Indexing (!) :: (IVector v a) => v a -> Int -> a -- | First element head :: (IVector v a) => v a -> a -- | Last element last :: (IVector v a) => v a -> a -- | Yield a part of the vector without copying it. Safer version of -- unsafeSlice. slice :: (IVector v a) => v a -> Int -> Int -> v a -- | Copy n elements starting at the given position to a new -- vector. extract :: (IVector v a) => v a -> Int -> Int -> v a -- | Yield the first n elements without copying. takeSlice :: (IVector v a) => Int -> v a -> v a -- | Copy the first n elements to a new vector. take :: (IVector v a) => Int -> v a -> v a -- | Yield all but the first n elements without copying. dropSlice :: (IVector v a) => Int -> v a -> v a -- | Copy all but the first n elements to a new vectors. drop :: (IVector v a) => Int -> v a -> v a (//) :: (IVector v a) => v a -> [(Int, a)] -> v a update :: (IVector v a, IVector v (Int, a)) => v a -> v (Int, a) -> v a bpermute :: (IVector v a, IVector v Int) => v a -> v Int -> v a -- | Map a function over a vector map :: (IVector v a, IVector v b) => (a -> b) -> v a -> v b -- | Zip two vectors with the given function. zipWith :: (IVector v a, IVector v b, IVector v c) => (a -> b -> c) -> v a -> v b -> v c zip :: (IVector v a, IVector v b, IVector v (a, b)) => v a -> v b -> v (a, b) eq :: (IVector v a, Eq a) => v a -> v a -> Bool cmp :: (IVector v a, Ord a) => v a -> v a -> Ordering -- | Drop elements which do not satisfy the predicate filter :: (IVector v a) => (a -> Bool) -> v a -> v a -- | Yield the longest prefix of elements satisfying the predicate without -- copying. takeWhileSlice :: (IVector v a) => (a -> Bool) -> v a -> v a -- | Copy the longest prefix of elements satisfying the predicate to a new -- vector takeWhile :: (IVector v a) => (a -> Bool) -> v a -> v a -- | Drop the longest prefix of elements that satisfy the predicate without -- copying dropWhileSlice :: (IVector v a) => (a -> Bool) -> v a -> v a -- | Drop the longest prefix of elements that satisfy the predicate and -- copy the rest to a new vector. dropWhile :: (IVector v a) => (a -> Bool) -> v a -> v a -- | Check whether the vector contains an element elem :: (IVector v a, Eq a) => a -> v a -> Bool -- | Inverse of elem notElem :: (IVector v a, Eq a) => a -> v a -> Bool -- | Yield Just the first element matching the predicate or -- Nothing if no such element exists. find :: (IVector v a) => (a -> Bool) -> v a -> Maybe a -- | Yield Just the index of the first element matching the -- predicate or Nothing if no such element exists. findIndex :: (IVector v a) => (a -> Bool) -> v a -> Maybe Int -- | Left fold foldl :: (IVector v b) => (a -> b -> a) -> a -> v b -> a -- | Lefgt fold on non-empty vectors foldl1 :: (IVector v a) => (a -> a -> a) -> v a -> a -- | Left fold with strict accumulator foldl' :: (IVector v b) => (a -> b -> a) -> a -> v b -> a -- | Left fold on non-empty vectors with strict accumulator foldl1' :: (IVector v a) => (a -> a -> a) -> v a -> a -- | Right fold foldr :: (IVector v a) => (a -> b -> b) -> b -> v a -> b -- | Right fold on non-empty vectors foldr1 :: (IVector v a) => (a -> a -> a) -> v a -> a -- | Prefix scan prescanl :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v a -- | Prefix scan with strict accumulator prescanl' :: (IVector v a, IVector v b) => (a -> b -> a) -> a -> v b -> v a -- | Convert a vector to a list toList :: (IVector v a) => v a -> [a] -- | Convert a list to a vector fromList :: (IVector v a) => [a] -> v a -- | Convert a vector to a Stream stream :: (IVector v a) => v a -> Stream a -- | Create a vector from a Stream unstream :: (IVector v a) => Stream a -> v a -- | Construct a pure vector from a monadic initialiser new :: (IVector v a) => New a -> v a -- | Boxed vectors module Data.Vector data Vector a Vector :: !!Int -> !!Int -> (Array# a) -> Vector a instance (Ord a) => Ord (Vector a) instance (Eq a) => Eq (Vector a) instance IVector Vector a -- | Unboxed vectors based on Unbox. module Data.Vector.Unboxed -- | Unboxed vectors data Vector a Vector :: !!Int -> !!Int -> ByteArray# -> Vector a instance (Unbox a, Ord a) => Ord (Vector a) instance (Unbox a, Eq a) => Eq (Vector a) instance (Unbox a) => IVector Vector a