Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- {-# LANGUAGE RecordWildCards #-}
- import Data.IORef
- import System.Clock
- data Timer =
- Timer {
- _timerRef :: !(IORef TimeSpec),
- _timerType :: !Clock
- }
- newTimer :: Clock -> IO Timer
- newTimer _timerType =
- fmap (\_timerRef -> Timer{..})
- (getTime _timerType >>= newIORef)
- timed :: Timer -> IO a -> IO a
- timed Timer{..} action = do
- t0 <- getTime _timerType
- r <- action
- t1 <- getTime _timerType
- let dt = t1 - t0
- r <$ atomicModifyIORef' _timerRef (\t -> (t + dt, ()))
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement