Safe Haskell | None |
---|---|
Language | Haskell2010 |
- data Stream a
- head :: Syntax a => Stream a -> a
- tail :: Syntax a => Stream a -> Stream a
- map :: (Syntax a, Syntax b) => (a -> b) -> Stream a -> Stream b
- mapNth :: Syntax a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream a
- maps :: Syntax a => [a -> a] -> Stream a -> Stream a
- intersperse :: Syntax a => a -> Stream a -> Stream a
- interleave :: Syntax a => Stream a -> Stream a -> Stream a
- downsample :: Syntax a => Data Index -> Stream a -> Stream a
- duplicate :: Syntax a => Data Index -> Stream a -> Stream a
- scan :: Syntax a => (a -> b -> a) -> a -> Stream b -> Stream a
- scan1 :: Syntax a => (a -> a -> a) -> Stream a -> Stream a
- mapAccum :: (Syntax acc, Syntax b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream b
- iterate :: Syntax a => (a -> a) -> a -> Stream a
- repeat :: Syntax a => a -> Stream a
- unfold :: (Syntax a, Syntax c) => (c -> (a, c)) -> c -> Stream a
- drop :: Syntax a => Data Length -> Stream a -> Stream a
- zip :: Stream a -> Stream b -> Stream (a, b)
- zipWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream c
- unzip :: (Syntax a, Syntax b) => Stream (a, b) -> (Stream a, Stream b)
- take :: Syntax a => Data Length -> Stream a -> Data [Internal a]
- splitAt :: Syntax a => Data Length -> Stream a -> (Data [Internal a], Stream a)
- cycle :: Syntax a => Vector a -> Stream a
- streamAsVector :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> Vector a -> Vector b
- streamAsVectorSize :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> (Data Length -> Data Length) -> Vector a -> Vector b
- recurrenceO :: Type a => Vector1 a -> (Vector1 a -> Data a) -> Stream (Data a)
- recurrenceI :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> (Vector1 a -> Data b) -> Stream (Data b)
- recurrenceIO :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> Vector1 b -> (Vector1 a -> Vector1 b -> Data b) -> Stream (Data b)
- recurrenceIIO :: (Type a, Type b, Type c) => Vector1 a -> Stream (Data a) -> Vector1 b -> Stream (Data b) -> Vector1 c -> (Vector1 a -> Vector1 b -> Vector1 c -> Data c) -> Stream (Data c)
- slidingAvg :: Data WordN -> Stream (Data WordN) -> Stream (Data WordN)
- iir :: Data Float -> Vector1 Float -> Vector1 Float -> Stream (Data Float) -> Stream (Data Float)
- fir :: Vector1 Float -> Stream (Data Float) -> Stream (Data Float)
Documentation
Infinite streams.
map :: (Syntax a, Syntax b) => (a -> b) -> Stream a -> Stream b Source
'map f str' transforms every element of the stream str
using the
function f
mapNth :: Syntax a => (a -> a) -> Data Index -> Data Index -> Stream a -> Stream a Source
'mapNth f n k str' transforms every n
th element with offset k
of the stream str
using the function f
maps :: Syntax a => [a -> a] -> Stream a -> Stream a Source
'maps fs str' uses one of the functions from fs
successively to modify
the elements of str
intersperse :: Syntax a => a -> Stream a -> Stream a Source
'intersperse a str' inserts an a
between each element of the stream
str
.
interleave :: Syntax a => Stream a -> Stream a -> Stream a Source
Create a new stream by alternating between the elements from the two input streams
downsample :: Syntax a => Data Index -> Stream a -> Stream a Source
'downsample n str' takes every n
th element of the input stream
duplicate :: Syntax a => Data Index -> Stream a -> Stream a Source
'duplicate n str' stretches the stream by duplicating the elements n
times
scan :: Syntax a => (a -> b -> a) -> a -> Stream b -> Stream a Source
'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.
scan1 :: Syntax a => (a -> a -> a) -> Stream a -> Stream a Source
A scan but without an initial element.
mapAccum :: (Syntax acc, Syntax b) => (acc -> a -> (acc, b)) -> acc -> Stream a -> Stream b Source
Maps a function over a stream using an accumulator.
iterate :: Syntax a => (a -> a) -> a -> Stream a Source
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)) ...]
unfold :: (Syntax a, Syntax c) => (c -> (a, c)) -> c -> Stream a Source
unfold f acc
creates a new stream by successively applying f
to
to the accumulator acc
.
drop :: Syntax a => Data Length -> Stream a -> Stream a Source
Drop a number of elements from the front of a stream
zipWith :: (a -> b -> c) -> Stream a -> Stream b -> Stream c Source
Pairs together two streams using a function to combine the corresponding elements.
unzip :: (Syntax a, Syntax b) => Stream (a, b) -> (Stream a, Stream b) Source
Given a stream of pairs, split it into two stream.
take :: Syntax a => Data Length -> Stream a -> Data [Internal a] Source
'take n str' allocates n
elements from the stream str
into a
core array.
splitAt :: Syntax a => Data Length -> Stream a -> (Data [Internal a], Stream 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 :: Syntax a => Vector a -> Stream a Source
Loops through a vector indefinitely to produce a stream.
streamAsVector :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> Vector a -> Vector 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 :: (Syntax a, Syntax b) => (Stream a -> Stream b) -> (Data Length -> Data Length) -> Vector a -> Vector 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 => Vector1 a -> (Vector1 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!0
and fib!1
refer to previous elements in the
stream defined one step back and two steps back respectively.
recurrenceI :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> (Vector1 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 WordN -> Stream (Data WordN) -> Stream (Data WordN) slidingAvg n str = recurrenceI (replicate n 0) str (\input -> sum input `quot` n)
recurrenceIO :: (Type a, Type b) => Vector1 a -> Stream (Data a) -> Vector1 b -> (Vector1 a -> Vector1 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.
recurrenceIIO :: (Type a, Type b, Type c) => Vector1 a -> Stream (Data a) -> Vector1 b -> Stream (Data b) -> Vector1 c -> (Vector1 a -> Vector1 b -> Vector1 c -> Data c) -> Stream (Data c) Source
Similar to recurrenceIO
but takes two input streams.