Skip to content

Instantly share code, notes, and snippets.

@rlupton20
Created October 13, 2015 20: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 rlupton20/0274a7eab045f248ee1d to your computer and use it in GitHub Desktop.
Save rlupton20/0274a7eab045f248ee1d to your computer and use it in GitHub Desktop.
reactimate simplifications for Yampa
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