reactive-banana-bunch
Safe HaskellNone
LanguageHaskell98

Reactive.Banana.Bunch.Frameworks

Synopsis

Documentation

data MomentIO a #

The MomentIO monad is used to add inputs and outputs to an event network.

Instances

Instances details
Applicative MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

pure :: a -> MomentIO a #

(<*>) :: MomentIO (a -> b) -> MomentIO a -> MomentIO b #

liftA2 :: (a -> b -> c) -> MomentIO a -> MomentIO b -> MomentIO c #

(*>) :: MomentIO a -> MomentIO b -> MomentIO b #

(<*) :: MomentIO a -> MomentIO b -> MomentIO a #

Functor MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

fmap :: (a -> b) -> MomentIO a -> MomentIO b #

(<$) :: a -> MomentIO b -> MomentIO a #

Monad MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

(>>=) :: MomentIO a -> (a -> MomentIO b) -> MomentIO b #

(>>) :: MomentIO a -> MomentIO b -> MomentIO b #

return :: a -> MomentIO a #

MonadFix MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

mfix :: (a -> MomentIO a) -> MomentIO a #

MonadIO MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

liftIO :: IO a -> MomentIO a #

MonadMoment MomentIO # 
Instance details

Defined in Reactive.Banana.Types

Methods

liftMoment :: Moment a -> MomentIO a #

Monoid a => Monoid (MomentIO a) # 
Instance details

Defined in Reactive.Banana.Types

Methods

mempty :: MomentIO a #

mappend :: MomentIO a -> MomentIO a -> MomentIO a #

mconcat :: [MomentIO a] -> MomentIO a #

Semigroup a => Semigroup (MomentIO a) # 
Instance details

Defined in Reactive.Banana.Types

Methods

(<>) :: MomentIO a -> MomentIO a -> MomentIO a #

sconcat :: NonEmpty (MomentIO a) -> MomentIO a #

stimes :: Integral b => b -> MomentIO a -> MomentIO a #

type Handler a = a -> IO () #

An event handler is a function that takes an event value and performs some computation.

data Future a #

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.

Instances

Instances details
Applicative Future # 
Instance details

Defined in Reactive.Banana.Types

Methods

pure :: a -> Future a #

(<*>) :: Future (a -> b) -> Future a -> Future b #

liftA2 :: (a -> b -> c) -> Future a -> Future b -> Future c #

(*>) :: Future a -> Future b -> Future b #

(<*) :: Future a -> Future b -> Future a #

Functor Future # 
Instance details

Defined in Reactive.Banana.Types

Methods

fmap :: (a -> b) -> Future a -> Future b #

(<$) :: a -> Future b -> Future a #

Monad Future # 
Instance details

Defined in Reactive.Banana.Types

Methods

(>>=) :: Future a -> (a -> Future b) -> Future b #

(>>) :: Future a -> Future b -> Future b #

return :: a -> Future a #

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

Expand
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 liftIO, we would have ended up with this error:

• 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 IO a and returns an (m a): liftIO, enabling us to run the program and see the expected results:

> evalStateT printState "hello"
"hello"

> evalStateT printState 3
3

plainChanges :: Behavior a -> MomentIO (Event a) Source #

This is a bit of a hack. The events will occur slightly after the behavior changes.