Created
October 13, 2015 20:32
-
-
Save rlupton20/0274a7eab045f248ee1d to your computer and use it in GitHub Desktop.
reactimate simplifications for Yampa
This file contains 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
module YampaUtils | |
( yampaMain, sReactimate ) where | |
import FRP.Yampa as Y | |
import Data.Time.Clock.POSIX | |
import Data.IORef | |
sReactimate :: IO a -> IO (DTime, Maybe a) -> (b -> IO Bool) -> SF a b -> IO () | |
sReactimate init inp out sigFun = Y.reactimate init (sInput inp) (sOutput out) sigFun | |
where sInput inp _ = inp | |
sOutput out _ = out | |
yampaMain :: IO a -> IO (Maybe a) -> (b -> IO Bool) -> SF a b -> IO () | |
yampaMain init input output sigFun = do | |
t <- getPOSIXTime | |
timeRef <- newIORef t | |
let timeWrapInput ins = do | |
inV <- ins | |
t' <- getPOSIXTime | |
t <- readIORef timeRef | |
let dt = realToFrac (t' - t) | |
writeIORef timeRef t' | |
return (dt, inV) | |
sReactimate init (timeWrapInput input) output sigFun |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment