- data Stream a
- head :: Syntactic a => Stream a -> a
- tail :: Syntactic a => Stream a -> Stream a
- map :: (Syntactic a, Syntactic b) => (a -> b) -> Stream a -> Stream b
- mapNth :: Syntactic a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream a
- maps :: Syntactic a => [a -> a] -> Stream a -> Stream a
- intersperse :: Syntactic a => a -> Stream a -> Stream a
- interleave :: Syntactic a => Stream a -> Stream a -> Stream a
- downsample :: Syntactic a => Data Index -> Stream a -> Stream a
- duplicate :: Syntactic a => Data Index -> Stream a -> Stream a
- scan :: Syntactic a => (a -> b -> a) -> a -> Stream b -> Stream a
- mapAccum :: (Syntactic acc, Syntactic b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream b
- iterate :: Syntactic a => (a -> a) -> a -> Stream a
- repeat :: Syntactic a => a -> Stream a
- unfold :: (Syntactic a, Syntactic c) => (c -> (a, c)) -> c -> Stream a
- drop :: Data Length -> Stream a -> Stream a
- zip :: Stream a -> Stream b -> Stream (a, b)
- zipWith :: Syntactic c => (a -> b -> c) -> Stream a -> Stream b -> Stream c
- unzip :: (Syntactic a, Syntactic b) => Stream (a, b) -> (Stream a, Stream b)
- take :: Type a => Data Length -> Stream (Data a) -> Data [a]
- splitAt :: Type a => Data Length -> Stream (Data a) -> (Data [a], Stream (Data a))
- cycle :: Syntactic a => Vector a -> Stream a
- streamAsVector :: (Type a, Type b) => (Stream (Data a) -> Stream (Data b)) -> Vector (Data a) -> Vector (Data b)
- streamAsVectorSize :: (Type a, Type b) => (Stream (Data a) -> Stream (Data b)) -> (Data Length -> Data Length) -> Vector (Data a) -> Vector (Data b)
- recurrenceO :: Type a => DVector a -> (DVector a -> Data a) -> Stream (Data a)
- recurrenceI :: (Type a, Type b) => DVector a -> Stream (Data a) -> (DVector a -> Data b) -> Stream (Data b)
- recurrenceIO :: (Type a, Type b) => DVector a -> Stream (Data a) -> DVector b -> (DVector a -> DVector b -> Data b) -> Stream (Data b)
- iir :: Data Float -> DVector Float -> DVector Float -> Stream (Data Float) -> Stream (Data Float)
- fir :: DVector Float -> Stream (Data Float) -> Stream (Data Float)

# Documentation

map :: (Syntactic a, Syntactic b) => (a -> b) -> Stream a -> Stream bSource

'map f str' transforms every element of the stream `str`

using the
function `f`

mapNth :: Syntactic a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream aSource

'mapNth f n k str' transforms every `n`

th element with offset `k`

of the stream `str`

using the function `f`

maps :: Syntactic a => [a -> a] -> Stream a -> Stream aSource

'maps fs str' uses one of the functions from `fs`

successively to modify
the elements of `str`

intersperse :: Syntactic a => a -> Stream a -> Stream aSource

'intersperse a str' inserts an `a`

between each element of the stream
`str`

.

interleave :: Syntactic a => Stream a -> Stream a -> Stream aSource

Create a new stream by alternating between the elements from the two input streams

downsample :: Syntactic a => Data Index -> Stream a -> Stream aSource

'downsample n str' takes every `n`

th element of the input stream

duplicate :: Syntactic a => Data Index -> Stream a -> Stream aSource

'duplicate n str' stretches the stream by duplicating the elements `n`

times

scan :: Syntactic a => (a -> b -> a) -> a -> Stream b -> Stream aSource

'scan f a str' produces a stream by successively applying `f`

to
each element of the input stream `str`

and the previous element of
the output stream.

mapAccum :: (Syntactic acc, Syntactic b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream bSource

Maps a function over a stream using an accumulator.

iterate :: Syntactic a => (a -> a) -> a -> Stream aSource

Iteratively applies a function to a starting element. All the successive results are used to create a stream.

iterate f a == [a, f a, f (f a), f (f (f a)) ...]

repeat :: Syntactic a => a -> Stream aSource

Repeat an element indefinitely.

repeat a = [a, a, a, ...]

unfold :: (Syntactic a, Syntactic c) => (c -> (a, c)) -> c -> Stream aSource

`unfold f acc`

creates a new stream by successively applying `f`

to
to the accumulator `acc`

.

drop :: Data Length -> Stream a -> Stream aSource

Drop a number of elements from the front of a stream

zipWith :: Syntactic c => (a -> b -> c) -> Stream a -> Stream b -> Stream cSource

Pairs together two streams using a function to combine the corresponding elements.

unzip :: (Syntactic a, Syntactic b) => Stream (a, b) -> (Stream a, Stream b)Source

Given a stream of pairs, split it into two stream.

take :: Type a => Data Length -> Stream (Data a) -> Data [a]Source

'take n str' allocates `n`

elements from the stream `str`

into a
core array.

splitAt :: Type a => Data Length -> Stream (Data a) -> (Data [a], Stream (Data a))Source

'splitAt n str' allocates `n`

elements from the stream `str`

into a
core array and returns the rest of the stream continuing from
element 'n+1'.

cycle :: Syntactic a => Vector a -> Stream aSource

Loops through a vector indefinitely to produce a stream.

streamAsVector :: (Type a, Type b) => (Stream (Data a) -> Stream (Data b)) -> Vector (Data a) -> Vector (Data b)Source

A convenience function for translating an algorithm on streams to an algorithm on vectors. The result vector will have the same length as the input vector. It is important that the stream function doesn't drop any elements of the input stream.

This function allocates memory for the output vector.

streamAsVectorSize :: (Type a, Type b) => (Stream (Data a) -> Stream (Data b)) -> (Data Length -> Data Length) -> Vector (Data a) -> Vector (Data b)Source

Similar to `streamAsVector`

except the size of the output array is computed by the second argument
which is given the size of the input vector as a result.

recurrenceO :: Type a => DVector a -> (DVector a -> Data a) -> Stream (Data a)Source

A combinator for descibing recurrence equations, or feedback loops. The recurrence equation may refer to previous outputs of the stream, but only as many as the length of the input stream It uses memory proportional to the input vector.

For exaple one can define the fibonacci sequence as follows:

fib = recurrenceO (vector [0,1]) (\fib -> fib!0 + fib!1)

The expressions `fib 1`

and `fib 2`

refer to previous elements in the
stream defined one step back and two steps back respectively.

recurrenceI :: (Type a, Type b) => DVector a -> Stream (Data a) -> (DVector a -> Data b) -> Stream (Data b)Source

A recurrence combinator with input. The function `recurrenceI`

is
similar to `recurrenceO`

. The difference is that that it has an input
stream, and that the recurrence equation may only refer to previous
inputs, it may not refer to previous outputs.

The sliding average of a stream can easily be implemented using
`recurrenceI`

.

slidingAvg :: Data DefaultWord -> Stream (Data DefaultWord) -> Stream (Data DefaultWord) slidingAvg n str = recurrenceI (replicate n 0) str (\input _ -> sum input `quot` n)

recurrenceIO :: (Type a, Type b) => DVector a -> Stream (Data a) -> DVector b -> (DVector a -> DVector b -> Data b) -> Stream (Data b)Source

`recurrenceIO`

is a combination of `recurrenceO`

and `recurrenceI`

. It
has an input stream and the recurrence equation may refer both to
previous inputs and outputs.

`recurrenceIO`

is used when defining the `iir`

filter.