0 | ||| Provides a data type for Monadic Stream Functions (MSFs)
1 | ||| together with associated interface implementations and
2 | ||| some core functionality.
3 | |||
4 | ||| An MSF is an effectful computation from an input of type `i`
5 | ||| to an output of type `o`, that can be described using a rich
6 | ||| library of combinators and evaluated using function
7 | ||| `Data.MSF.Running.step`,
8 | ||| which not only produces an output for every input value
9 | ||| but also a new MSF to be used in the next evaluation step.
16 | --------------------------------------------------------------------------------
17 | -- n-ary sums
18 | --------------------------------------------------------------------------------
20 | ||| A monadic stream function (`MSF`) is used to
21 | ||| convert streams of input values of type `i` to
22 | ||| output values of type `o` in a monadic context `m`.
23 | |||
24 | ||| The [dunai](https://hackage.haskell.org/package/dunai)
25 | ||| library implements them as
26 | ||| `data MSF m i o = MSF (i -> m (o, MSF m i o))`
27 | ||| but this most general form does not go well with
28 | ||| the Idris totality checker.
29 | |||
30 | ||| It is therefore implemented as a set of primitive
31 | ||| constructors, some of which are truly primitives,
32 | ||| some of which are there for reasons of efficiency.
33 | ||| In later versions of this library, `MSF` might
34 | ||| no longer be publicly exported, so client code should
35 | ||| use the provided combinators instead of accessing the
36 | ||| data constructors directly.
37 | |||
38 | ||| `MSF` objects can be stepwise evaluated by invoking
39 | ||| function `Data.MSF.Running.step`.
43 | ||| A heterogeneous list of MSFs all of which
44 | ||| accept the same input type. This is used for
45 | ||| broadcasting an input value across several MSFs,
46 | ||| collecting the result as an n-ary product.
47 | ||| See also function `fan`.
52 | ||| A heterogeneous list of MSFs all of which
53 | ||| produce the same type of outup. This is used for
54 | ||| choosing a single MSF for producing a result based
55 | ||| on an n-ary sum as input. See also function `collect`.
60 | ||| A heterogeneous list of MSFs. This is used both
61 | ||| for running several unrelated MSFs in parallel, in
62 | ||| which case it takes an n-ary product as input
63 | ||| and produces an n-ary product as output (see
64 | ||| function `par`), as well as for selecting a single
65 | ||| MSF to run based on an n-ary sum as input, in which
66 | ||| case a value of an n-ary sum is produced as output
67 | ||| (see function `choice` for this use case).
76 | ||| The identity MSF
79 | ||| The constant MSF
82 | ||| Lifts a pure function to an MSF
85 | ||| Lifts an effectful computation to an MSF
88 | ||| Sequencing of MSFs
91 | ||| Parallelising MSFs
94 | ||| Broadcasting a value to a list of MSFs
95 | ||| all taking the same input
98 | ||| Choosing an MSF based on an n-ary sum as input
101 | ||| Choosing an MSF (all of which produce the same output)
102 | ||| based on an n-ary sum as input
105 | ||| Feedback loops (stateful computations)
108 | ||| Single time switching: Upon the first event,
109 | ||| the second stream function is calculated,
110 | ||| evaluated immediately and used henceforth.
113 | --------------------------------------------------------------------------------
114 | -- Lifting Primitives
115 | --------------------------------------------------------------------------------
117 | ||| The identity MSF
122 | ||| A constant MSF
127 | ||| Lifting a pure function to an MSF
132 | ||| Lifting an effectful computation to an MSF
137 | ||| Lifting a value in a context to an MSF
142 | --------------------------------------------------------------------------------
143 | -- Sequencing MSFs
144 | --------------------------------------------------------------------------------
148 | ||| Sequencing of MSFs
153 | --------------------------------------------------------------------------------
154 | -- Paralellising MSFs
155 | --------------------------------------------------------------------------------
157 | ||| Runs a bundle of MSFs in parallel. This is
158 | ||| a generalization of `(***)` from `Control.Arrow`.
163 | ||| Broadcasts an input value across a list of MSFs,
164 | ||| all of which must accept the same type of input.
165 | ||| This is a generalization of `(&&&)` from `Control.Arrow`.
170 | ||| Apply a binary function to the result of running
171 | ||| two MSFs in parallel.
176 | --------------------------------------------------------------------------------
177 | -- Selecting MSFs
178 | --------------------------------------------------------------------------------
180 | ||| Choose an MSF to run depending the input value
181 | ||| This is a generalization of `(+++)` from `Control.Arrow`.
186 | ||| Choose an MSF all of which produce the same output.
187 | ||| This is a generalization of `(\|/)` from `Control.Arrow`.
192 | --------------------------------------------------------------------------------
193 | -- Loops and Stateful computations
194 | --------------------------------------------------------------------------------
196 | ||| Feedback loops: Given an initial state value,
197 | ||| we can feedback the result of each evaluation
198 | ||| step and us it as the new state for the next step.
203 | --------------------------------------------------------------------------------
204 | -- Interfaces
205 | --------------------------------------------------------------------------------