Control.Arrow.SF
 Contents Category Lift Products Sums Loop (product) Loop (sum) Delay State machine Delta / merge Maybe
Description

This module contains the classic stream transformer arrow, defined by

newtype SF a b = SF { unSF :: a -> (b, SF a b) }

together with the standard (and some not-that-standard) combinators.

In particular, we take the viewpoint that each operation for products (pairs) have to have a dual for sums (Either). Unfortunately, the Arrow class breaks this symmetry: It favours products by putting the lifting of pure functions there, which should in a separate class instead (there are interesting arrows without meaningful lifting from Haskell functions).

Synopsis
newtype SF a b = SF {
 unSF :: a -> (b, SF a b)
}
runSF :: SF a b -> [a] -> [b]
sf_id :: SF a a
sf_comp :: SF a b -> SF b c -> SF a c
sf_arr :: (a -> b) -> SF a b
sf_first :: SF a b -> SF (a, x) (b, x)
sf_second :: SF a b -> SF (x, a) (x, b)
sf_left :: SF a b -> SF (Either a x) (Either b x)
sf_right :: SF a b -> SF (Either x a) (Either x b)
sf_loop :: SF (a, s) (b, s) -> SF a b
sf_eitherLoop :: SF (Either a c) (Either b c) -> SF a b
sf_init :: a -> SF a a
sf_loopD :: s -> ((a, s) -> (b, s)) -> SF a b
sf_mealy_ :: s -> (a -> s -> (b, s)) -> SF a b
sf_mealy :: s -> (a -> s -> (b, s)) -> SF a (b, s)
sf_eitherMachine :: s -> (Either a s -> Either b s) -> SF a b
sf_delta :: SF a (a, a)
sf_merge :: SF (Either a a) a
sf_compMaybe :: SF a (Maybe b) -> SF b c -> SF a (Maybe c)
sf_liftMaybe :: SF a b -> SF (Maybe a) (Maybe b)
sf_justA :: SF a (Maybe a)
sf_nothingA :: SF x (Maybe a)
Documentation
 newtype SF a b Source
Constructors
SF
 unSF :: a -> (b, SF a b) Instances
 Arrow SF ArrowChoice SF ArrowLoop SF Category SF
 runSF :: SF a b -> [a] -> [b] Source
Category
 sf_id :: SF a a Source
 sf_comp :: SF a b -> SF b c -> SF a c Source
Lift
 sf_arr :: (a -> b) -> SF a b Source
Products
 sf_first :: SF a b -> SF (a, x) (b, x) Source
 sf_second :: SF a b -> SF (x, a) (x, b) Source
Sums
 sf_left :: SF a b -> SF (Either a x) (Either b x) Source
 sf_right :: SF a b -> SF (Either x a) (Either x b) Source
Loop (product)
 sf_loop :: SF (a, s) (b, s) -> SF a b Source
Loop (sum)
 sf_eitherLoop :: SF (Either a c) (Either b c) -> SF a b Source
The dual of loop.
Delay
 sf_init :: a -> SF a a Source
An initialized delay.
 sf_loopD :: s -> ((a, s) -> (b, s)) -> SF a b Source
Loop with delay (that is, a state machine).
State machine
 sf_mealy_ :: s -> (a -> s -> (b, s)) -> SF a b Source
This is actually equivalent to sf_loopD.
 sf_mealy :: s -> (a -> s -> (b, s)) -> SF a (b, s) Source
 sf_eitherMachine :: s -> (Either a s -> Either b s) -> SF a b Source
This is the dual of sf_loopD. It looks a bit strange, but basically what happens is that state transitions happen only when then input triggers them, and meantime it is sleeping, remembering the old state. The new state will depend only on the input when the transition was triggered, and the new output will depend on the old state.
Delta / merge
 sf_delta :: SF a (a, a) Source
These are actually pure functions.
 sf_merge :: SF (Either a a) a Source
Maybe
 sf_compMaybe :: SF a (Maybe b) -> SF b c -> SF a (Maybe c) Source
 sf_liftMaybe :: SF a b -> SF (Maybe a) (Maybe b) Source
 sf_justA :: SF a (Maybe a) Source
This is a pure function, too.
 sf_nothingA :: SF x (Maybe a) Source