Safe Haskell | None |
---|---|
Language | Haskell98 |
Reactive.Banana.Bunch.Frameworks
Synopsis
- data MomentIO a
- type Handler a = a -> IO ()
- data AddHandler a
- newAddHandler :: IO (AddHandler a, Handler a)
- fromAddHandler :: AddHandler a -> MomentIO (Event a)
- fromChanges :: a -> AddHandler a -> MomentIO (Behavior a)
- data Future a
- compile :: MomentIO () -> IO EventNetwork
- actuate :: EventNetwork -> IO ()
- pause :: EventNetwork -> IO ()
- liftIO :: MonadIO m => IO a -> m a
- changes :: Behavior a -> MomentIO (Event (Future a))
- newEvent :: MomentIO (Event a, Handler a)
- reactimate :: Event (IO ()) -> MomentIO ()
- reactimate' :: Event (Future (IO ())) -> MomentIO ()
- plainChanges :: Behavior a -> MomentIO (Event a)
Documentation
The MomentIO
monad is used to add inputs and outputs
to an event network.
Instances
Applicative MomentIO # | |
Functor MomentIO # | |
Monad MomentIO # | |
MonadFix MomentIO # | |
Defined in Reactive.Banana.Types | |
MonadIO MomentIO # | |
Defined in Reactive.Banana.Types | |
MonadMoment MomentIO # | |
Defined in Reactive.Banana.Types Methods liftMoment :: Moment a -> MomentIO a # | |
Monoid a => Monoid (MomentIO a) # | |
Semigroup a => Semigroup (MomentIO a) # | |
An event handler is a function that takes an event value and performs some computation.
data AddHandler a Source #
newAddHandler :: IO (AddHandler a, Handler a) Source #
fromAddHandler :: AddHandler a -> MomentIO (Event a) Source #
fromChanges :: a -> AddHandler a -> MomentIO (Behavior a) Source #
The Future
monad is just a helper type for the changes
function.
A value of type Future a
is only available in the context
of a reactimate
but not during event processing.
compile :: MomentIO () -> IO EventNetwork #
Compile the description of an event network
into an EventNetwork
that you can actuate
, pause
and so on.
actuate :: EventNetwork -> IO () #
Actuate an event network. The inputs will register their event handlers, so that the networks starts to produce outputs in response to input events.
pause :: EventNetwork -> IO () #
Pause an event network. Immediately stop producing output. (In a future version, it will also unregister all event handlers for inputs.) Hence, the network stops responding to input events, but it's state will be preserved.
You can resume the network with actuate
.
Note: You can stop a network even while it is processing events,
i.e. you can use pause
as an argument to reactimate
.
The network will not stop immediately though, only after
the current event has been processed completely.
liftIO :: MonadIO m => IO a -> m a #
Lift a computation from the IO
monad.
This allows us to run IO computations in any monadic stack, so long as it supports these kinds of operations
(i.e. IO
is the base monad for the stack).
Example
import Control.Monad.Trans.State -- from the "transformers" library printState :: Show s => StateT s IO () printState = do state <- get liftIO $ print state
Had we omitted
, we would have ended up with this error:liftIO
• Couldn't match type ‘IO’ with ‘StateT s IO’ Expected type: StateT s IO () Actual type: IO ()
The important part here is the mismatch between StateT s IO ()
and
.IO
()
Luckily, we know of a function that takes an
and returns an IO
a(m a)
:
,
enabling us to run the program and see the expected results:liftIO
> evalStateT printState "hello" "hello" > evalStateT printState 3 3