Advertisement
Guest User

Untitled

a guest
Nov 20th, 2014
192
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.12 KB | None | 0 0
  1. {-# LANGUAGE RankNTypes #-}
  2. module Main where
  3.  
  4. import Reactive.Banana
  5. import Reactive.Banana.Frameworks
  6. import Reactive.Banana.Switch
  7. import Data.IORef
  8. import Control.Monad
  9.  
  10. main = do
  11. fShowRef <- newIORef (const (return ()))
  12. fNumRef <- newIORef (const (return ()))
  13. let
  14. netDesc :: forall t. Frameworks t => Moment t ()
  15. netDesc = do
  16. (eNum, fNum) <- newEvent
  17. (eShow, fShow) <- newEvent
  18. liftIO (writeIORef fShowRef fShow)
  19. liftIO (writeIORef fNumRef fNum)
  20. let beh = stepper 0 eNum
  21. behTrimmed <- trimB beh
  22. reactimate (printInitial behTrimmed <$ eShow)
  23.  
  24. actuate =<< compile netDesc
  25.  
  26. fNum <- readIORef fNumRef
  27. fNum 1
  28. fShow <- readIORef fShowRef
  29. fShow ()
  30.  
  31. printInitial :: AnyMoment Behavior Int -> IO ()
  32. printInitial beh = do
  33. let
  34. netDesc :: forall t. Frameworks t => Moment t ()
  35. netDesc = do
  36. behNow <- now beh
  37. initVal <- initial behNow
  38. liftIO (print initVal)
  39. -- compiling is enough, I just want to see the initial value
  40. void (compile netDesc)
  41.  
  42. 1
  43.  
  44. 0
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement