Safe Haskell  Safe 

Language  Haskell98 
 See the Data.Repa.Vector.Unboxed module for examples of how these functions can be used.
 data Chain m s a = Chain {
 mchainSize :: Size
 mchainState :: s
 mchainStep :: s > m (Step s a)
 data Step s a
 liftChain :: Monad m => Chain Identity s a > Chain m s a
 resumeChain :: Monad m => s > Chain m s a > Chain m s a
 weaveC :: Monad m => (k > Option aL > Option aR > m (Turn k aX)) > k > Chain m sL aL > Chain m sR aR > Chain m (Weave sL aL sR aR k) aX
 data Weave sL aL sR aR k
 data Turn k a
 data Move
 move :: k > Move > Weave s1 a1 s2 a2 k > Weave s1 a1 s2 a2 k
 foldsC :: Monad m => (a > b > m b) > b > Option3 n Int b > Chain m sLen (n, Int) > Chain m sVal a > Chain m (Folds sLen sVal n a b) (n, b)
 data Folds sLens sVals n a b = Folds {
 _stateLens :: !sLens
 _stateVals :: !sVals
 _nameSeg :: !(Option n)
 _lenSeg :: !Int
 _valSeg :: !b
 unfoldsC :: Monad m => (a > k > m (StepUnfold k b)) > k > Chain m s a > Chain m (s, k, Option a) b
 data StepUnfold s a
 = StepUnfoldGive a s
  StepUnfoldNext a s
  StepUnfoldBump s
  StepUnfoldFinish s
 scanMaybeC :: Monad m => (k > a > m (k, Maybe b)) > k > Chain m s a > Chain m (s, k) b
 groupsByC :: Monad m => (a > a > m Bool) > Maybe (a, Int) > Chain m s a > Chain m (s, Maybe (a, Int)) (a, Int)
Chain Fusion
A chain is an abstract, stateful producer of elements. It is similar a stream as used in stream fusion, except that internal state is visible in its type. This allows the computation to be paused and resumed at a later point.
Chain  

Result of a chain computation step.
liftChain :: Monad m => Chain Identity s a > Chain m s a Source
Lift a pure chain to a monadic chain.
resumeChain :: Monad m => s > Chain m s a > Chain m s a Source
Resume a chain computation from a previous state.
Weaves
:: Monad m  
=> (k > Option aL > Option aR > m (Turn k aX))  Worker function. 
> k  Initial state. 
> Chain m sL aL  Left input chain. 
> Chain m sR aR  Right input chain. 
> Chain m (Weave sL aL sR aR k) aX  Result chain. 
A weave is a generalized merge of two input chains.
The worker function takes the current state, values from the
left and right input chains, and produces a Turn
which
describes any output at that point, as well as how the input
chains should be advanced.
What to do after considering two input elements.
How to move the input chains after considering to input elements.
move :: k > Move > Weave s1 a1 s2 a2 k > Weave s1 a1 s2 a2 k Source
Apply a Move
instruction to a weave state.
Folding
:: Monad m  
=> (a > b > m b)  Worker function. 
> b  Initial state when folding rest of segments. 
> Option3 n Int b  Name, length and initial state for first segment. 
> Chain m sLen (n, Int)  Segment names and lengths. 
> Chain m sVal a  Input data to fold. 
> Chain m (Folds sLen sVal n a b) (n, b) 
Segmented fold over vectors of segment lengths and input values.
The total lengths of all segments need not match the length of the
input elements vector. The returned Folds
state can be inspected
to determine whether all segments were completely folded, or the
vector of segment lengths or elements was too short relative to the
other.
data Folds sLens sVals n a b Source
Return state of a folds operation.
Folds  

Unfolding
:: Monad m  
=> (a > k > m (StepUnfold k b))  Worker function. 
> k  Initial state for the unfold. 
> Chain m s a  Input elements. 
> Chain m (s, k, Option a) b  Output elements. 
Segmented unfold.
The worker function takes the current element from the input stream and current state.
If the worker returns Just x then that output element will be placed in the output stream, and it will be called again with the same input elemenent and next state.
If the worker returns Nothing then we advance to the next element of the input stream.
data StepUnfold s a Source
StepUnfoldGive a s  
StepUnfoldNext a s  
StepUnfoldBump s  
StepUnfoldFinish s 
(Show s, Show a) => Show (StepUnfold s a) Source 
Scanning
:: Monad m  
=> (k > a > m (k, Maybe b))  Worker function. 
> k  Initial state for scan. 
> Chain m s a  Input elements. 
> Chain m (s, k) b  Output elements and final state. 
Perform a lefttoright scan through an input vector, maintaining a state value between each element. For each element of input we may or may not produce an element of output.