-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Unified interface for primitive arrays -- -- This package provides a typeclass Contiguous that offers a -- unified interface to working with Array, SmallArray, -- PrimArray, and UnliftedArray. @package contiguous @version 0.5.2 -- | The contiguous typeclass parameterises over a contiguous array type. -- This allows us to have a common API to a number of contiguous array -- types and their mutable counterparts. module Data.Primitive.Contiguous -- | The size of the array size :: (Contiguous arr, Element arr b) => arr b -> Int -- | The size of the mutable array sizeMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> m Int -- | Test whether the array is empty. null :: Contiguous arr => arr b -> Bool -- | Index into an array at the given index. index :: (Contiguous arr, Element arr b) => arr b -> Int -> b -- | Index into an array at the given index, yielding an unboxed one-tuple -- of the element. index# :: (Contiguous arr, Element arr b) => arr b -> Int -> (# b #) -- | Read a mutable array at the given index. read :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m b -- | Indexing in a monad. -- -- The monad allows operations to be strict in the array when necessary. -- Suppose array copying is implemented like this: -- --
--   copy mv v = ... write mv i (v ! i) ...
--   
-- -- For lazy arrays, v ! i would not be not be evaluated, which -- means that mv would unnecessarily retain a reference to -- v in each element written. -- -- With indexM, copying can be implemented like this instead: -- --
--   copy mv v = ... do
--     x <- indexM v i
--     write mv i x
--   
-- -- Here, no references to v are retained because indexing (but -- not the elements) is evaluated eagerly. indexM :: (Contiguous arr, Element arr b, Monad m) => arr b -> Int -> m b -- | The empty array. empty :: Contiguous arr => arr a -- | Allocate a new mutable array of the given size. new :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> m (Mutable arr (PrimState m) b) -- | Create a singleton array. singleton :: (Contiguous arr, Element arr a) => a -> arr a -- | Create a doubleton array. doubleton :: (Contiguous arr, Element arr a) => a -> a -> arr a -- | Create a tripleton array. tripleton :: (Contiguous arr, Element arr a) => a -> a -> a -> arr a -- | Create a quadrupleton array. quadrupleton :: (Contiguous arr, Element arr a) => a -> a -> a -> a -> arr a -- | replicate n x is an array of length n with -- x the value of every element. replicate :: (Contiguous arr, Element arr a) => Int -> a -> arr a -- | replicateMutable n x is a mutable array of length -- n with x the value of every element. replicateMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Int -> b -> m (Mutable arr (PrimState m) b) -- | Construct an array of the given length by applying the function to -- each index. generate :: (Contiguous arr, Element arr a) => Int -> (Int -> a) -> arr a -- | Construct an array of the given length by applying the monadic action -- to each index. generateM :: (Contiguous arr, Element arr a, Monad m) => Int -> (Int -> m a) -> m (arr a) -- | Construct a mutable array of the given length by applying the function -- to each index. generateMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> a) -> m (Mutable arr (PrimState m) a) -- | Apply a function n times to a value and construct an array -- where each consecutive element is the result of an additional -- application of this function. The zeroth element is the original -- value. -- --
--   iterateN 5 (+ 1) 0 = fromListN 5 [0,1,2,3,4]
--   
iterateN :: (Contiguous arr, Element arr a) => Int -> (a -> a) -> a -> arr a -- | Apply a function n times to a value and construct a mutable -- array where each consecutive element is the result of an additional -- application of this function. The zeroth element is the original -- value. iterateMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> a) -> a -> m (Mutable arr (PrimState m) a) -- | Write to a mutable array at the given index. write :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> b -> m () -- | Run an effectful computation that produces an array. run :: Contiguous arr => (forall s. ST s (arr a)) -> arr a -- | replicateMutableM n act performs the action n times, -- gathering the results. replicateMutableM :: (PrimMonad m, Contiguous arr, Element arr a) => Int -> m a -> m (Mutable arr (PrimState m) a) -- | Construct a mutable array of the given length by applying the monadic -- action to each index. generateMutableM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (Int -> m a) -> m (Mutable arr (PrimState m) a) -- | Apply a monadic function n times to a value and construct a -- mutable array where each consecutive element is the result of an -- additional application of this function. The zeroth element is the -- original value. iterateMutableNM :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> (a -> m a) -> a -> m (Mutable arr (PrimState m) a) -- | Execute the monad action and freeze the resulting array. create :: (Contiguous arr, Element arr a) => (forall s. ST s (Mutable arr s a)) -> arr a -- | Execute the monadic action and freeze the resulting array. createT :: (Contiguous arr, Element arr a, Traversable f) => (forall s. ST s (f (Mutable arr s a))) -> f (arr a) -- | Construct an array by repeatedly applying a generator function to a -- seed. The generator function yields Just the next element and -- the new seed or Nothing if there are no more elements. -- --
--   >>> unfoldr (\n -> if n == 0 then Nothing else Just (n,n-1) 10
--       <10,9,8,7,6,5,4,3,2,1>
--   
unfoldr :: (Contiguous arr, Element arr a) => (b -> Maybe (a, b)) -> b -> arr a -- | Construct an array with at most n elements by repeatedly applying the -- generator function to a seed. The generator function yields -- Just the next element and the new seed or Nothing if -- there are no more elements. unfoldrN :: (Contiguous arr, Element arr a) => Int -> (b -> Maybe (a, b)) -> b -> arr a -- | Construct a mutable array by repeatedly applying a generator function -- to a seed. The generator function yields Just the next element -- and the new seed or Nothing if there are no more elements. -- --
--   >>> unfoldrMutable (\n -> if n == 0 then Nothing else Just (n,n-1) 10
--       <10,9,8,7,6,5,4,3,2,1>
--   
unfoldrMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (b -> Maybe (a, b)) -> b -> m (Mutable arr (PrimState m) a) -- | Yield an array of the given length containing the values x, -- succ x, succ (succ x) etc. enumFromN :: (Contiguous arr, Element arr a, Enum a) => a -> Int -> arr a -- | Yield a mutable array of the given length containing the values x, -- succ x, succ (succ x) etc. enumFromMutableN :: (Contiguous arr, Element arr a, PrimMonad m, Enum a) => a -> Int -> m (Mutable arr (PrimState m) a) -- | Append two arrays. append :: (Contiguous arr, Element arr a) => arr a -> arr a -> arr a -- | Insert an element into an array at the given index. insertAt :: (Contiguous arr, Element arr a) => arr a -> Int -> a -> arr a -- | Copy a slice of an array an then insert an element into that array. -- -- The default implementation performs a memset which would be -- unnecessary except that the garbage collector might trace the -- uninitialized array. insertSlicing :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> Int -> b -> arr b -- | Create a copy of an array except the element at the index is replaced -- with the given value. replaceAt :: (Contiguous arr, Element arr a) => arr a -> Int -> a -> arr a modifyAt :: (Contiguous arr, Element arr a) => (a -> a) -> arr a -> Int -> arr a -- | Variant of modifyAt that forces the result before installing it in the -- array. modifyAt' :: (Contiguous arr, Element arr a) => (a -> a) -> arr a -> Int -> arr a modifyAtF :: (Contiguous arr, Element arr a, Functor f) => (a -> f a) -> arr a -> Int -> f (arr a) -- | Variant of modifyAtF that forces the result before installing it in -- the array. Note that this requires Monad rather than -- Functor. modifyAtF' :: (Contiguous arr, Element arr a, Monad f) => (a -> f a) -> arr a -> Int -> f (arr a) -- | Reverse the elements of an array. reverse :: (Contiguous arr, Element arr a) => arr a -> arr a -- | Reverse the elements of a mutable array, in-place. reverseMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m () -- | Reverse the elements of a slice of a mutable array, in-place. reverseSlice :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> Int -> Int -> m () -- | Resize an array into one with the given size. resize :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> m (Mutable arr (PrimState m) b) -- | Map over the elements of an array. -- -- Note that because a new array must be created, the resulting array -- type can be different than the original. map :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c -- | Map strictly over the elements of an array. -- -- Note that because a new array must be created, the resulting array -- type can be different than the original. map' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (b -> c) -> arr1 b -> arr2 c -- | Map over a mutable array, modifying the elements in place. mapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () -- | Strictly map over a mutable array, modifying the elements in place. mapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (a -> a) -> Mutable arr (PrimState m) a -> m () -- | Map over the elements of an array with the index. imap :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c -- | Map strictly over the elements of an array with the index. -- -- Note that because a new array must be created, the resulting array -- type can be different than the original. imap' :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 c) => (Int -> b -> c) -> arr1 b -> arr2 c -- | Map over a mutable array with indices, modifying the elements in -- place. imapMutable :: (Contiguous arr, Element arr a, PrimMonad m) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () -- | Strictly map over a mutable array with indices, modifying the elements -- in place. imapMutable' :: (PrimMonad m, Contiguous arr, Element arr a) => (Int -> a -> a) -> Mutable arr (PrimState m) a -> m () -- | Modify the elements of a mutable array in-place. modify :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () -- | Strictly modify the elements of a mutable array in-place. modify' :: (Contiguous arr, Element arr a, PrimMonad m) => (a -> a) -> Mutable arr (PrimState m) a -> m () -- | The mapMaybe function is a version of map which can -- throw out elements. In particular, the functional arguments returns -- something of type Maybe b. If this is Nothing, -- no element is added on to the result array. If it is Just -- b, then b is included in the result array. mapMaybe :: forall arr1 arr2 a b. (Contiguous arr1, Element arr1 a, Contiguous arr2, Element arr2 b) => (a -> Maybe b) -> arr1 a -> arr2 b -- | zip takes two arrays and returns an array of corresponding -- pairs. -- --
--   zip [1, 2] ['a', 'b'] = [(1, 'a'), (2, 'b')]
--   
-- -- If one input array is shorter than the other, excess elements of the -- longer array are discarded: -- --
--   zip [1] ['a', 'b'] = [(1, 'a')]
--   zip [1, 2] ['a'] = [(1, 'a')]
--   
zip :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 (a, b)) => arr1 a -> arr2 b -> arr3 (a, b) -- | zipWith generalises zip by zipping with the function -- given as the first argument, instead of a tupling function. For -- example, zipWith (+) is applied to two arrays to produce an -- array of the corresponding sums. zipWith :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 c) => (a -> b -> c) -> arr1 a -> arr2 b -> arr3 c -- | Variant of zipWith that provides the index of each pair of -- elements. izipWith :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 a, Element arr2 b, Element arr3 c) => (Int -> a -> b -> c) -> arr1 a -> arr2 b -> arr3 c -- | Swap the elements of the mutable array at the given indices. swap :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> Int -> Int -> m () -- | Drop elements that do not satisfy the predicate. filter :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> arr a -- | Drop elements that do not satisfy the predicate which is applied to -- values and their indices. ifilter :: (Contiguous arr, Element arr a) => (Int -> a -> Bool) -> arr a -> arr a -- | The catMaybes function takes a list of Maybes and -- returns a list of all the Just values. catMaybes :: (Contiguous arr, Element arr a, Element arr (Maybe a)) => arr (Maybe a) -> arr a -- | Extracts from an array of Either all the Left elements. -- All the Left elements are extracted in order. lefts :: forall arr a b. (Contiguous arr, Element arr a, Element arr (Either a b)) => arr (Either a b) -> arr a -- | Extracts from an array of Either all the Right elements. -- All the Right elements are extracted in order. rights :: forall arr a b. (Contiguous arr, Element arr b, Element arr (Either a b)) => arr (Either a b) -> arr b -- | Partitions an array of Either into two arrays. All the -- Left elements are extracted, in order, to the first component -- of the output. Similarly the Right elements are extracted to -- the second component of the output. partitionEithers :: forall arr a b. (Contiguous arr, Element arr a, Element arr b, Element arr (Either a b)) => arr (Either a b) -> (arr a, arr b) -- | find takes a predicate and an array, and returns the leftmost -- element of the array matching the prediate, or Nothing if there -- is no such element. find :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> Maybe a -- | findIndex takes a predicate and an array, and returns the index -- of the leftmost element of the array matching the prediate, or -- Nothing if there is no such element. findIndex :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> Maybe Int -- | Does the element occur in the structure? elem :: (Contiguous arr, Element arr a, Eq a) => a -> arr a -> Bool -- | The largest element of a structure. maximum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a -- | The least element of a structure. minimum :: (Contiguous arr, Element arr a, Ord a) => arr a -> Maybe a -- | The largest element of a structure with respect to the given -- comparison function. maximumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a -- | The least element of a structure with respect to the given comparison -- function. minimumBy :: (Contiguous arr, Element arr a) => (a -> a -> Ordering) -> arr a -> Maybe a -- | Test the two arrays for equality. equals :: (Contiguous arr, Element arr b, Eq b) => arr b -> arr b -> Bool -- | Test the two mutable arrays for pointer equality. Does not check -- equality of elements. equalsMutable :: Contiguous arr => Mutable arr s a -> Mutable arr s a -> Bool -- | This function does not behave deterministically. Optimization level -- and inlining can affect its results. However, the one thing that can -- be counted on is that if it returns True, the two immutable -- arrays are definitely the same. This is useful as shortcut for -- equality tests. However, keep in mind that a result of False -- tells us nothing about the arguments. same :: Contiguous arr => arr a -> arr a -> Bool -- | Left fold over the elements of an array. foldl :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b -- | Strict left fold over the elements of an array. foldl' :: (Contiguous arr, Element arr a) => (b -> a -> b) -> b -> arr a -> b -- | Right fold over the element of an array. foldr :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b -- | Strict right fold over the elements of an array. foldr' :: (Contiguous arr, Element arr a) => (a -> b -> b) -> b -> arr a -> b -- | Monoidal fold over the element of an array. foldMap :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m -- | Strict monoidal fold over the elements of an array. foldMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m -- | Strict left monoidal fold over the elements of an array. foldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (a -> m) -> arr a -> m -- | Strict left fold over the elements of an array, where the accumulating -- function cares about the index of the element. ifoldl' :: (Contiguous arr, Element arr a) => (b -> Int -> a -> b) -> b -> arr a -> b -- | Strict right fold over the elements of an array, where the -- accumulating function cares about the index of the element. ifoldr' :: (Contiguous arr, Element arr a) => (Int -> a -> b -> b) -> b -> arr a -> b -- | Strict monoidal fold over the elements of an array. ifoldlMap' :: (Contiguous arr, Element arr a, Monoid m) => (Int -> a -> m) -> arr a -> m -- | Strict monoidal fold over the elements of an array. ifoldlMap1' :: (Contiguous arr, Element arr a, Semigroup m) => (Int -> a -> m) -> arr a -> m -- | Strict left monadic fold over the elements of an array. foldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> a -> m b) -> b -> arr a -> m b -- | Strict left monadic fold over the elements of an array. ifoldlM' :: (Contiguous arr, Element arr a, Monad m) => (b -> Int -> a -> m b) -> b -> arr a -> m b -- | The sum of a collection of actions, generalizing concat. -- --
--   >>> asum (C.fromList ['Just' "Hello", 'Nothing', Just "World"] :: Array String)
--   Just "Hello"
--   
asum :: (Contiguous arr, Element arr (f a), Alternative f) => arr (f a) -> f a all :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> Bool any :: (Contiguous arr, Element arr a) => (a -> Bool) -> arr a -> Bool -- | Variant of zipWith that accepts an accumulator, performing a -- lazy right fold over both arrays. foldrZipWith :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> b -> c -> c) -> c -> arr1 a -> arr2 b -> c -- | Variant of foldrZipWith that provides the index of each pair of -- elements. ifoldrZipWith :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> a -> b -> c -> c) -> c -> arr1 a -> arr2 b -> c -- | Variant of zipWith that accepts an accumulator, performing a -- strict left monadic fold over both arrays. foldlZipWithM' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => (c -> a -> b -> m c) -> c -> arr1 a -> arr2 b -> m c -- | Variant of 'foldlZipWithM'' that provides the index of each pair of -- elements. ifoldlZipWithM' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => (Int -> c -> a -> b -> m c) -> c -> arr1 a -> arr2 b -> m c -- | Map each element of the array to an action, evaluate these actions -- from left to right, and collect the results. For a version that -- ignores the results, see traverse_. traverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (a -> f b) -> arr1 a -> f (arr2 b) -- | Map each element of the array to an action, evaluate these actions -- from left to right, and ignore the results. For a version that doesn't -- ignore the results, see traverse. traverse_ :: (Contiguous arr, Element arr a, Applicative f) => (a -> f b) -> arr a -> f () -- | Map each element of the array and its index to an action, evaluating -- these actions from left to right. itraverse :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => (Int -> a -> f b) -> arr1 a -> f (arr2 b) -- | Map each element of the array and its index to an action, evaluate -- these actions from left to right, and ignore the results. For a -- version that doesn't ignore the results, see itraverse. itraverse_ :: (Contiguous arr, Element arr a, Applicative f) => (Int -> a -> f b) -> arr a -> f () -- | Map each element of the array to an action, evaluate these actions -- from left to right, and collect the results in a new array. traverseP :: (PrimMonad m, Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (a -> m b) -> arr1 a -> m (arr2 b) -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and collect the results. for a version -- that ignores the results see mapM_. mapM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => (a -> m b) -> arr1 a -> m (arr2 b) -- | forM is mapM with its arguments flipped. For a version -- that ignores its results, see forM_. forM :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Monad m) => arr1 a -> (a -> m b) -> m (arr2 b) -- | Map each element of a structure to a monadic action, evaluate these -- actions from left to right, and ignore the results. For a version that -- doesn't ignore the results see mapM. -- -- mapM_ = traverse_ mapM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => (a -> f b) -> arr a -> f () -- | forM_ is mapM_ with its arguments flipped. For a version -- that doesn't ignore its results, see forM. forM_ :: (Contiguous arr, Element arr a, Element arr b, Applicative f) => arr a -> (a -> f b) -> f () -- | for is traverse with its arguments flipped. For a -- version that ignores the results see for_. for :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b, Applicative f) => arr1 a -> (a -> f b) -> f (arr2 b) -- | for_ is traverse_ with its arguments flipped. For a -- version that doesn't ignore the results see for. -- --
--   >>> for_ (C.fromList [1..4] :: PrimArray Int) print
--   1
--   2
--   3
--   4
--   
for_ :: (Contiguous arr, Element arr a, Applicative f) => arr a -> (a -> f b) -> f () -- | Evaluate each action in the structure from left to right and collect -- the results. For a version that ignores the results see -- sequence_. sequence :: (Contiguous arr1, Contiguous arr2, Element arr1 (f a), Element arr2 a, Applicative f) => arr1 (f a) -> f (arr2 a) -- | Evaluate each action in the structure from left to right and ignore -- the results. For a version that doesn't ignore the results see -- sequence. sequence_ :: (Contiguous arr, Element arr (f a), Applicative f) => arr (f a) -> f () -- | Replace all locations in the input with the same value. -- -- Equivalent to Data.Functor.<$. (<$) :: (Contiguous arr1, Contiguous arr2, Element arr1 b, Element arr2 a) => a -> arr1 b -> arr2 a -- | Sequential application. -- -- Equivalent to Control.Applicative.<*>. ap :: (Contiguous arr1, Contiguous arr2, Contiguous arr3, Element arr1 (a -> b), Element arr2 a, Element arr3 b) => arr1 (a -> b) -> arr2 a -> arr3 b -- | scanl is similar to foldl, but returns an array of -- successive reduced values from the left: -- --
--   scanl f z [x1, x2, ...] = [z, f z x1, f (f z x1) x2, ...]
--   
-- -- Note that -- --
--   last (toList (scanl f z xs)) == foldl f z xs.
--   
scanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b -- | A strictly accumulating version of scanl. scanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b -- | A variant of scanl whose function argument takes the current -- index as an argument. iscanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b -- | A strictly accumulating version of iscanl. iscanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b -- | A prescan. -- --
--   prescanl f z = init . scanl f z
--   
-- -- Example: prescanl (+) 0 <1,2,3,4> = <0,1,3,6> prescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b -- | Like prescanl, but with a strict accumulator. prescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (b -> a -> b) -> b -> arr1 a -> arr2 b -- | A variant of prescanl where the function argument takes the -- current index of the array as an additional argument. iprescanl :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b -- | Like iprescanl, but with a strict accumulator. iprescanl' :: (Contiguous arr1, Contiguous arr2, Element arr1 a, Element arr2 b) => (Int -> b -> a -> b) -> b -> arr1 a -> arr2 b mapAccum' :: forall arr1 arr2 a b c. (Contiguous arr1, Contiguous arr2, Element arr1 b, Element arr2 c, Monoid a) => (b -> (a, c)) -> arr1 b -> (a, arr2 c) -- | Monadic accumulating strict left fold over the elements on an array. mapAccumLM' :: (Contiguous arr1, Contiguous arr2, Element arr1 b, Element arr2 c, Monad m) => (a -> b -> m (a, c)) -> a -> arr1 b -> m (a, arr2 c) -- | Convert a list into an array. fromList :: (Contiguous arr, Element arr a) => [a] -> arr a -- | Given an Int that is representative of the length of the list, -- convert the list into a mutable array of the given length. -- -- Note: calls error if the given length is incorrect. fromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a -- | Convert a list into a mutable array of the given length. fromListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => [a] -> m (Mutable arr (PrimState m) a) -- | Given an Int that is representative of the length of the list, -- convert the list into a mutable array of the given length. -- -- Note: calls error if the given length is incorrect. fromListMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) -- | Create an array from a list. If the given length does not match the -- actual length, this function has undefined behavior. unsafeFromListN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a -- | Create an array from a list, reversing the order of the elements. If -- the given length does not match the actual length, this function has -- undefined behavior. unsafeFromListReverseN :: (Contiguous arr, Element arr a) => Int -> [a] -> arr a -- | Create a mutable array from a list, reversing the order of the -- elements. If the given length does not match the actual length, this -- function has undefined behavior. unsafeFromListReverseMutableN :: (Contiguous arr, Element arr a, PrimMonad m) => Int -> [a] -> m (Mutable arr (PrimState m) a) -- | Convert an array to a list. toList :: (Contiguous arr, Element arr a) => arr a -> [a] -- | Convert a mutable array to a list. toListMutable :: (Contiguous arr, Element arr a, PrimMonad m) => Mutable arr (PrimState m) a -> m [a] -- | Convert one type of array into another. convert :: (Contiguous arr1, Element arr1 b, Contiguous arr2, Element arr2 b) => arr1 b -> arr2 b -- | Lift an ArrayArray# into an array. lift :: Contiguous arr => ArrayArray# -> arr b -- | Unlift an array into an ArrayArray#. unlift :: Contiguous arr => arr b -> ArrayArray# -- | Clone a slice of an array. clone :: (Contiguous arr, Element arr b) => arr b -> Int -> Int -> arr b -- | Clone a slice of a mutable array. cloneMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (Mutable arr (PrimState m) b) -- | Copy a slice of an array into a mutable array. copy :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> arr b -> Int -> Int -> m () -- | Copy a slice of a mutable array into another mutable array. In the -- case that the destination and source arrays are the same, the regions -- may overlap. copyMutable :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Mutable arr (PrimState m) b -> Int -> Int -> m () -- | Turn a mutable array into an immutable one with copying, using a slice -- of the mutable array. freeze :: (Contiguous arr, PrimMonad m, Element arr b) => Mutable arr (PrimState m) b -> Int -> Int -> m (arr b) -- | Copy a slice of an immutable array into a new mutable array. thaw :: (Contiguous arr, PrimMonad m, Element arr b) => arr b -> Int -> Int -> m (Mutable arr (PrimState m) b) -- | Turn a mutable array into an immutable one without copying. The -- mutable array should not be used after this conversion. unsafeFreeze :: (Contiguous arr, PrimMonad m) => Mutable arr (PrimState m) b -> m (arr b) -- | Lift an accumulating hash function over the elements of the array, -- returning the final accumulated hash. liftHashWithSalt :: (Contiguous arr, Element arr a) => (Int -> a -> Int) -> Int -> arr a -> Int -- | Reduce the array and all of its elements to WHNF. rnf :: (Contiguous arr, NFData a, Element arr a) => arr a -> () -- | The Contiguous typeclass as an interface to a multitude of -- contiguous structures. class Contiguous (arr :: Type -> Type) where { -- | The Mutable counterpart to the array. type family Mutable arr = (r :: Type -> Type -> Type) | r -> arr; -- | The constraint needed to store elements in the array. type family Element arr :: Type -> Constraint; } -- | A typeclass that is satisfied by all types. This is used used to -- provide a fake constraint for Array and SmallArray. class Always a -- | Boxed arrays data Array a -- | Mutable boxed arrays associated with a primitive state token. data MutableArray s a data SmallArray a data SmallMutableArray s a -- | Arrays of unboxed elements. This accepts types like Double, -- Char, Int, and Word, as well as their -- fixed-length variants (Word8, Word16, etc.). Since -- the elements are unboxed, a PrimArray is strict in its -- elements. This differs from the behavior of Array, which is -- lazy in its elements. data PrimArray a -- | Mutable primitive arrays associated with a primitive state token. -- These can be written to and read from in a monadic context that -- supports sequencing such as IO or ST. Typically, a -- mutable primitive array will be built and then convert to an immutable -- primitive array using unsafeFreezePrimArray. However, it is -- also acceptable to simply discard a mutable primitive array since it -- lives in managed memory and will be garbage collected when no longer -- referenced. data MutablePrimArray s a data UnliftedArray a data MutableUnliftedArray s a instance Data.Primitive.Contiguous.Contiguous Data.Primitive.SmallArray.SmallArray instance Data.Primitive.Contiguous.Contiguous Data.Primitive.PrimArray.PrimArray instance Data.Primitive.Contiguous.Contiguous Data.Primitive.Array.Array instance Data.Primitive.Contiguous.Contiguous Data.Primitive.Unlifted.Array.UnliftedArray instance Data.Primitive.Contiguous.Always a