Arrow based stream transducers http://github.com/as-capabl/machinecell
|Latest on Hackage:||4.0.0|
This package is not currently in any snapshots. If you're interested in using it, we recommend adding it to Stackage Nightly. Doing so will make builds more reliable, and allow stackage.org to host generated Haddocks.
Arrow based stream transducer.
As other iteratee or pipe libraries, machinecell abstracts general iteration processes.
Here is an example that is a simple iteration over a list.
>>> run (evMap (+1)) [1, 2, 3] [2, 3, 4]
In above statement, "
evMap (+1)" has a type "ProcessA (->) (Event Int) (Event Int)",
which denotes "A stream transducer that takes a series of Int as input,
gives a series of Int as output, run on base arrow (->)."
In addition to this simple iteration, machinecell has following features.
- Side effects
- Composite pipelines
- Arrow compositions
- Behaviours and switches
See Control.Arrow.Machine documentation.
Comparison to other libraries.
Some part of machinecell is similar to other stream transducer libraries, namely pipes, conduit, or machines. machinecell can be seen as a restricted variation of them to one-directional. But additionally, machinecell supports arrow compositions. Bidirectional communications can be taken place by ArrowLoop feature.
Rather, there are several other arrowised stream transducer libraries. streamproc shares the most concept to machinecell. But actually it has a problem described later in this post. Machinecell can be said as "Streamproc done right."
auto is a brand-new arrowised stream transducer library. Compared to it, machinecell's advantage is await/yield coroutines, while auto's one is serialization.
Motivation and background
"Generalizing monads to arrows," The original paper of arrow calculation mentions a kind of stream transducer, which later implemented as streamproc.
And other people propose instance declarations of Arrow class for several existing stream processors.
But actually, there is a problem argued in this post.
The core problem is, while arrow uses tuples as parallel data stream, they cannot represent a composite streams if they carry different numbers of data in parallel.
To solve this problem, some arrow libraries restrict transducers to one-to-one data transformation. Yampa and netwire does so, as mentioned in above post. And auto also takes this approach.
Machinecell's approach is different, but simple too. The key idea is wrapping all types of data stream into a maybe-like type. Then even tuples can represent different numbers of data, by inserting appropreate number of 'Nothing's.
Furthermore, I identified the maybe-like type as the 'Event' type, which appears in Yampa and netwire. Then I successively implemented several arrows of Yampa and netwire.
API names come from stream libraries are named after machines', while ones from FRPs are after Yampa's. Now, machinecell may be seen as a hybrid of machines and Yampa.
Breaking changes of APIs
- Side-effects are represented by
Monads rather than
- Replace the base arrow
ProcessAis now type alias for compatibility
- Change the signatures of construction functions
- Change the signatures of running functions
- Replace the base arrow
- Change the
- Add method
endout of the type class
- Add method
ZeroEvent. Change the signatures of blocking sources with it.
- Add type classes
- Modify again the versions of depending packages.
- Make the default of 'arrow-tr' flag False.
Modify the versions of depending packages.
- Correct a space leak problem
- Generalize some functions
- construct, repeatedly
- filterEvent, filterJust, filterLeft, filterRight
- Add arrow-tr flag
- Num instance definition
- Add source utilities
- Change a switching behavior. With previous implementation, a switching doesn't occur
when a runnning transducer emits a trigger event using
Fix performance issue of switch, dSwitch, accum, dAccum.
- ArrowLoop instance now independent of base arrow's
- Make PlanT newtype and add stop handling MonadPlus instance
- API changes
- Deleted Show and Eq instance of Event type
- Added Isos of ArrowUtil module
- Delete state monad handling.
- Delete unsafe primitives
- Delete deperecated
- Delete ProcessA ArrowReader instance and added
- Slightly changed the ArrowLoop instance declaration.
- Right tightening rule will be preserved.
- For IO processes, "Indefinite access to MVar" errors, which used to occur in some situations in old versions, will be suppressed.
- This will not change any existing code unless it loops back any Event-type signal.
- Relocate files
catchand its families are moved to Misc.Exception
- Performance improve
- Added primitives:
- Added to Misc:
- Deleted deprecated:
Occasional'by splitting some members from
(Fix test suite of 1.3.0)
- Support of
- Added utilities related to
- Correct EOS behaviour of some utilities.
- Support of
- Added await fail handling.
- Improved performance by church-encoded free monads.
- Arrow stack of newest GHC support for some utilities.
Eliminated banana brackets to support newest GHC.
Eventconstructors and some instances (
- Fix some bugs of core part.
- First release.