box-0.0.1.5: boxes

Safe HaskellNone
LanguageHaskell2010

Box.Transducer

Description

Synopsis

Documentation

newtype Transducer s a b Source #

transduction wiki says: "A transducer is a device that converts energy from one form to another." Translated to context, this Transducer converts a stream of type a to a stream of a different type.

Constructors

Transducer 

Fields

Instances
Category (Transducer s :: Type -> Type -> Type) Source # 
Instance details

Defined in Box.Transducer

Methods

id :: Transducer s a a #

(.) :: Transducer s b c -> Transducer s a b -> Transducer s a c #

etc :: MonadConc m => s -> Transducer s a b -> Cont m (Box (STM m) b a) -> m s Source #

emit - transduce - commit

with etc, you're in the box, and inside the box, there are no effects: just a stream of as, pure functions and state tracking. It's a nice way to code, and very friendly for the compiler. When the committing and emitting is done, the box collapses to state.

The combination of an input tape, an output tape, and a state-based stream computation lends itself to the etc computation as a finite-state transducer or mealy machine.

etcM :: (MonadConc m, MonadBase m m) => s -> Transducer s a b -> Cont m (Box m b a) -> m s Source #

asPipe :: Monad m => Pipe a b (StateT s m) () -> Stream (Of a) (StateT s m) () -> Stream (Of b) (StateT s m) () Source #

convert a Pipe to a Transducer