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

Language | Haskell2010 |

Useful auxiliary functions and definitions.

- type MStream m a = MSF m () a
- type MSink m a = MSF m a ()
- insert :: Monad m => MSF m (m a) a
- arrM_ :: Monad m => m b -> MSF m a b
- (^>>>) :: MonadBase m1 m2 => MSF m1 a b -> MSF m2 b c -> MSF m2 a c
- (>>>^) :: MonadBase m1 m2 => MSF m2 a b -> MSF m1 b c -> MSF m2 a c
- mapMSF :: Monad m => MSF m a b -> MSF m [a] [b]
- mapMaybeS :: Monad m => MSF m a b -> MSF m (Maybe a) (Maybe b)
- withSideEffect :: Monad m => (a -> m b) -> MSF m a a
- withSideEffect_ :: Monad m => m b -> MSF m a a
- iPost :: Monad m => b -> MSF m a b -> MSF m a b
- next :: Monad m => b -> MSF m a b -> MSF m a b
- count :: (Num n, Monad m) => MSF m a n
- sumS :: (RModule v, Monad m) => MSF m v v
- sumFrom :: (RModule v, Monad m) => v -> MSF m v v
- mappendS :: (Monoid n, Monad m) => MSF m n n
- mappendFrom :: (Monoid n, Monad m) => n -> MSF m n n
- accumulateWith :: Monad m => (a -> s -> s) -> s -> MSF m a s
- unfold :: Monad m => (a -> (b, a)) -> a -> MSF m () b
- repeatedly :: Monad m => (a -> a) -> a -> MSF m () a
- embed_ :: (Functor m, Monad m) => MSF m a () -> [a] -> m ()
- trace :: Show a => String -> MSF IO a a
- traceWith :: (Monad m, Show a) => (String -> m ()) -> String -> MSF m a a
- traceWhen :: (Monad m, Show a) => (a -> Bool) -> (String -> m ()) -> String -> MSF m a a
- pauseOn :: Show a => (a -> Bool) -> String -> MSF IO a a

# Streams and sinks

type MStream m a = MSF m () a Source #

A stream is an MSF that produces outputs ignoring the input. It can obtain the values from a monadic context.

type MSink m a = MSF m a () Source #

A stream is an MSF that produces outputs producing no output. It can consume the values with side effects.

# Lifting

insert :: Monad m => MSF m (m a) a Source #

Deprecated: Don't use this. arrM id instead

Pre-inserts an input sample.

(^>>>) :: MonadBase m1 m2 => MSF m1 a b -> MSF m2 b c -> MSF m2 a c Source #

Lift the first MSF into the monad of the second.

(>>>^) :: MonadBase m1 m2 => MSF m2 a b -> MSF m1 b c -> MSF m2 a c Source #

Lift the second MSF into the monad of the first.

# Analogues of map and fmap

# Adding side effects

withSideEffect :: Monad m => (a -> m b) -> MSF m a a Source #

Applies a function to produce an additional side effect and passes the input unchanged.

withSideEffect_ :: Monad m => m b -> MSF m a a Source #

Produces an additional side effect and passes the input unchanged.

# Delays

iPost :: Monad m => b -> MSF m a b -> MSF m a b Source #

Preprends a fixed output to an MSF. The first input is completely ignored.

next :: Monad m => b -> MSF m a b -> MSF m a b Source #

Preprends a fixed output to an MSF, shifting the output.

# Folding

## Folding for VectorSpace instances

count :: (Num n, Monad m) => MSF m a n Source #

Count the number of simulation steps. Produces 1, 2, 3,...

sumFrom :: (RModule v, Monad m) => v -> MSF m v v Source #

Sums the inputs, starting from an initial vector.

## Folding for monoids

mappendFrom :: (Monoid n, Monad m) => n -> MSF m n n Source #

Accumulate the inputs, starting from an initial monoid value.

## Generic folding / accumulation

accumulateWith :: Monad m => (a -> s -> s) -> s -> MSF m a s Source #

Applies a function to the input and an accumulator, outputing the
accumulator. Equal to `f s0 -> feedback s0 $ arr (uncurry f >>> dup)`

.

# Unfolding

unfold :: Monad m => (a -> (b, a)) -> a -> MSF m () b Source #

Generate outputs using a step-wise generation function and an initial value.

repeatedly :: Monad m => (a -> a) -> a -> MSF m () a Source #

Generate outputs using a step-wise generation function and an initial
value. Version of `unfold`

in which the output and the new accumulator
are the same. Should be equal to `f a -> unfold (f >>> dup) a`

.

# Running functions

embed_ :: (Functor m, Monad m) => MSF m a () -> [a] -> m () Source #

Run an MSF fed from a list, discarding results. Useful when one needs to combine effects and streams (i.e., for testing purposes).

# Debugging

trace :: Show a => String -> MSF IO a a Source #

Outputs every input sample, with a given message prefix.

traceWith :: (Monad m, Show a) => (String -> m ()) -> String -> MSF m a a Source #

Outputs every input sample, with a given message prefix, using an auxiliary printing function.