on 511fe85 help sign in
streamly/docs/transformers.md
32 lines 1.2 kB history raw
1## Using Monad Transformers
3Common monad transformers can be used with streamly serial streams, without any
4issues. `ReaderT` can be used with concurrent streams as well without any
5issues.
7The semantics of monads other than `ReaderT` with concurrent streams are
8not yet finalized and will change in future, therefore as of now they are not
9recommended to be used with concurrent streams.
11## Ordering of Monad Transformers
13In most cases it is a good idea to keep streamly as the top level monad.
15## State Sharing
16### Serial Applications
18Read only global state can always be shared using the `Reader` monad.
19Read-write global state can be shared either using an `IORef` in the `Reader`
20monad or using the `State` monad.
22See `AcidRain.hs` example for a usage of `StateT` in the serially executing
23portion of the program.
25### Concurrent Applications
27The current recommended method for sharing modifiable global state across
28concurrent tasks is to put the shared state inside an `IORef` in a `Reader`
29monad or just share the `IORef` by passing it to the required functions. The
30`IORef` can be updated atomically using `atomicModifyIORef`.
32The `CirclingSquare.hs` example shares an `IORef` across parallel tasks.