Created
November 10, 2013 10:48
-
-
Save funrep/7396687 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{-# 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