{-# LANGUAGE CPP, FlexibleContexts, FlexibleInstances, UndecidableInstances #-}
#if __GLASGOW_HASKELL__ < 710
{-# LANGUAGE OverlappingInstances #-}
#endif
module Control.Monad.Time (MonadTime(..)) where
import Control.Monad.Trans
import Control.Monad.Reader (ReaderT, ask)
import Data.Time
class Monad m => MonadTime m where
currentTime :: m UTCTime
instance MonadTime IO where
currentTime = getCurrentTime
instance {-# OVERLAPPING #-} Monad m => MonadTime (ReaderT UTCTime m) where
currentTime = ask
instance {-# OVERLAPPABLE #-} (
MonadTime m
, MonadTrans t
, Monad (t m)
) => MonadTime (t m) where
currentTime = lift currentTime