public
Created

Reactive Banana as Library

  • Download Gist
Main.hs
Haskell
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28
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

Please sign in to comment on this gist.

Something went wrong with that request. Please try again.