Skip to content

Instantly share code, notes, and snippets.

@aforemny
Created June 27, 2012 14:32
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save aforemny/3004430 to your computer and use it in GitHub Desktop.
Save aforemny/3004430 to your computer and use it in GitHub Desktop.
Reactive Banana as Library
module Main where
import Control.Concurrent (forkIO, threadDelay)
import Control.Monad (forever)
import Data.Time (getCurrentTime)
import Reactive.Banana
main = do
(clock, clockSink) <- newAddHandler
forkIO $ forever $ getCurrentTime >>= clockSink >> sleep
(int, intSink) <- newAddHandler
forkIO $ mapM_ ((>> sleep) . intSink) [1..]
time0 <- getCurrentTime
library $ do
clockB <- fromChanges time0 clock
intB <- fromChanges 0 int
return $ liftA2 (\s t -> show s ++ " " ++ show t) clockB intB
where
sleep = threadDelay (10^6)
library subnet = do
network <- compile $ do
stringE <- changes =<< subnet
reactimate $ print <$> stringE
actuate network
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment