Skip to content

Instantly share code, notes, and snippets.

@funrep
Created November 10, 2013 10:48
Show Gist options
  • Save funrep/7396687 to your computer and use it in GitHub Desktop.
Save funrep/7396687 to your computer and use it in GitHub Desktop.
{-# LANGUAGE RankNTypes #-}
import Control.Monad (when)
import Reactive.Banana
import Reactive.Banana.Frameworks
main = do
source <- newAddHandler
network <- setupNetwork source
actuate network
eventLoop source
eventLoop :: EventSource () -> IO ()
eventLoop esEvent = loop
where
loop = do
s <- getLine
case s of
"event" -> return () >>= snd esEvent
_ -> return ()
when (s /= "quit") loop
type EventSource a = (AddHandler a, a -> IO ())
setupNetwork :: EventSource () -> IO EventNetwork
setupNetwork esEvent = compile $ do
eEvent <- fromAddHandler $ fst esEvent
reactimate $ fmap react eEvent
where
react _ = putStrLn "react"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment