Safe Haskell | Safe |
---|---|

Language | Haskell2010 |

## Synopsis

- sumFrom :: Monad m => Integer -> Cell m Integer Integer
- count :: Monad m => Cell m a Integer
- foldC :: (Data b, Monad m) => (a -> b -> b) -> b -> Cell m a b
- foldC' :: (Data b, Monad m) => (a -> b -> b) -> b -> Cell m a b
- keep :: (Data a, Monad m) => a -> Cell m (Maybe a) a
- keepJust :: (Monad m, Data a) => Cell m (Maybe a) (Maybe a)
- boundedFIFO :: (Data a, Monad m) => Int -> Cell m (Maybe a) (Seq a)
- edge :: Monad m => Cell m Bool Bool
- printTime :: MonadIO m => String -> m ()
- printTimeC :: MonadIO m => String -> Cell m () ()
- data BufferCommand a
- maybePush :: Maybe a -> [BufferCommand a]
- maybePop :: Maybe a -> [BufferCommand b]
- buffer :: (Monad m, Data a) => Cell m [BufferCommand a] (Maybe a)
- buffered :: (Monad m, Data a) => Cell m (Maybe a) (Maybe b) -> Cell m (Maybe a) (Maybe b)

# State accumulation

sumFrom :: Monad m => Integer -> Cell m Integer Integer Source #

Sum all past inputs, starting by the given number

foldC :: (Data b, Monad m) => (a -> b -> b) -> b -> Cell m a b Source #

Accumulate all incoming data,
using the given fold function and start value.
For example, if

receives inputs `foldC`

f b`a0`

, `a1`

,...
it will output `b`

, `f a0 b`

, `f a1 $ f a0 b`

, and so on.

foldC' :: (Data b, Monad m) => (a -> b -> b) -> b -> Cell m a b Source #

Like `foldC`

, but does not delay the output.

keep :: (Data a, Monad m) => a -> Cell m (Maybe a) a Source #

Initialise with a value `a`

.
If the input is `Nothing`

, `keep a`

will output the stored indefinitely.
A new value can be stored by inputting 'Maybe a'.

boundedFIFO :: (Data a, Monad m) => Int -> Cell m (Maybe a) (Seq a) Source #

`boundedFIFO n`

keeps the first `n`

present values.

# Debugging utilities

printTime :: MonadIO m => String -> m () Source #

Print the current UTC time, prepended with the first 8 characters of the given message.

# Buffers

data BufferCommand a Source #

A command to send to `buffer`

.

buffered :: (Monad m, Data a) => Cell m (Maybe a) (Maybe b) -> Cell m (Maybe a) (Maybe b) Source #

- Whenever

value enters`Just`

a`buffered cell`

, it is added to the buffer. - Whenever
`cell`

emits

, the oldest value is dropped from the buffer.`Just`

b `cell`

is always fed with`Just`

the oldest value from the buffer, except when the buffer is empty, then it is fed`Nothing`

.

This construction guarantees that `cell`

produces exactly one output for every input value.