Copyright | (c) 2019 Commonwealth Scientific and Industrial Research Organisation (CSIRO) |
---|---|
License | BSD-3 |
Maintainer | dave.laing.80@gmail.com |
Safe Haskell | None |
Language | Haskell2010 |
BasicGuest
provides instances that most reflex
programs need:
MonadIO
MonadFix
MonadSample
MonadHold
NotReady
PostBuild
PerformEvent
—
hasPerformable
(BasicGuest
t m)MonadIO
TriggerEvent
Adjustable
For some simple usage examples, see the examples directory
Synopsis
- data BasicGuest t (m :: * -> *) a
- type BasicGuestConstraints t (m :: * -> *) = (MonadReflexHost t m, MonadHold t m, MonadSample t m, Ref m ~ Ref IO, MonadRef (HostFrame t), Ref (HostFrame t) ~ Ref IO, MonadIO (HostFrame t), PrimMonad (HostFrame t), MonadIO m, MonadFix m)
- basicHostWithQuit :: (forall t m. BasicGuestConstraints t m => BasicGuest t m (a, Event t ())) -> IO a
- basicHostForever :: (forall t m. BasicGuestConstraints t m => BasicGuest t m a) -> IO a
- repeatUntilQuit :: BasicGuestConstraints t m => IO a -> Event t () -> BasicGuest t m ()
Documentation
data BasicGuest t (m :: * -> *) a Source #
Instances
type BasicGuestConstraints t (m :: * -> *) = (MonadReflexHost t m, MonadHold t m, MonadSample t m, Ref m ~ Ref IO, MonadRef (HostFrame t), Ref (HostFrame t) ~ Ref IO, MonadIO (HostFrame t), PrimMonad (HostFrame t), MonadIO m, MonadFix m) Source #
basicHostWithQuit :: (forall t m. BasicGuestConstraints t m => BasicGuest t m (a, Event t ())) -> IO a Source #
Run a BasicGuest
The program will exit when the Event
returned by the BasicGuest
fires
basicHostForever :: (forall t m. BasicGuestConstraints t m => BasicGuest t m a) -> IO a Source #
Run a BasicGuest
without a quit Event
:: BasicGuestConstraints t m | |
=> IO a | Action to repeatedly run |
-> Event t () |
|
-> BasicGuest t m () |
Augment a BasicGuest
with an action that is repeatedly run until
the provided event fires
Example - providing a 'tick' Event
to a network
myNetwork :: (Reflex t, MonadHold t m, MonadFix m) => Event t () -> m (Dynamic t Int) myNetwork eTick = count eTick myGuest :: BasicGuestConstraints t m => BasicGuest t m ((), Event t ()) myGuest = do (eTick, sendTick) <- newTriggerEvent dCount <- myNetwork eTick let eCountUpdated = updated dCount eQuit = () <$ ffilter (==5) eCountUpdated repeatUntilQuit eQuit (threadDelay 1000000 *> sendTick ()) performEvent_ $ liftIO . print <$> eCountUpdated pure ((), eQuit) main :: IO () main = basicHostWithQuit myGuest