{-# LANGUAGE CPP #-}
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE ScopedTypeVariables #-}
{-# LANGUAGE RankNTypes #-}
{-# LANGUAGE DataKinds #-}
{-# LANGUAGE FlexibleInstances #-}
{-# LANGUAGE GeneralizedNewtypeDeriving #-}
{-# LANGUAGE MultiParamTypeClasses #-}
{-# LANGUAGE UnboxedTuples #-}
{-# LANGUAGE UndecidableInstances #-}
{-# LANGUAGE PolyKinds #-}

-- | An implementation of `Control.Monad.Time.MonadTime` with a monad transformer.
module Control.Monad.Trans.SimulatedTime
  ( SimulatedTimeT (..),
    runSimulatedTimeT,
    RealTimeT(..),
    getTimeEnv,
    module Test.SimulatedTime
  )
where

import Control.Applicative (Alternative)
import qualified Control.Concurrent
import Control.Monad.Catch (MonadCatch, MonadMask(..), MonadThrow)
import Control.Monad.Cont (MonadCont)
import Control.Monad.Except (MonadError)
import Control.Monad.Primitive (PrimMonad)
import Control.Monad.RWS (MonadState, MonadWriter)
import Control.Monad.Reader
import Control.Monad.Time
import Control.Monad.Trans.Resource (MonadResource)
import Control.Monad.Zip (MonadZip)
import qualified Data.Time
import Control.Monad.IO.Unlift
import Test.SimulatedTime

#if __GLASGOW_HASKELL__ < 880
import Control.Monad.Fail (MonadFail(..))
#endif

-- | A newtype wrapper over `ReaderT` `TimeEnv`
newtype SimulatedTimeT m a = SimulatedTimeT {SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT :: ReaderT TimeEnv m a}
  deriving
    ( a -> SimulatedTimeT m b -> SimulatedTimeT m a
(a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b
(forall a b. (a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b)
-> (forall a b. a -> SimulatedTimeT m b -> SimulatedTimeT m a)
-> Functor (SimulatedTimeT m)
forall a b. a -> SimulatedTimeT m b -> SimulatedTimeT m a
forall a b. (a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b
forall (m :: * -> *) a b.
Functor m =>
a -> SimulatedTimeT m b -> SimulatedTimeT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> SimulatedTimeT m b -> SimulatedTimeT m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> SimulatedTimeT m b -> SimulatedTimeT m a
fmap :: (a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> SimulatedTimeT m a -> SimulatedTimeT m b
Functor,
      Functor (SimulatedTimeT m)
a -> SimulatedTimeT m a
Functor (SimulatedTimeT m)
-> (forall a. a -> SimulatedTimeT m a)
-> (forall a b.
    SimulatedTimeT m (a -> b)
    -> SimulatedTimeT m a -> SimulatedTimeT m b)
-> (forall a b c.
    (a -> b -> c)
    -> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c)
-> (forall a b.
    SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b)
-> (forall a b.
    SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a)
-> Applicative (SimulatedTimeT m)
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a
SimulatedTimeT m (a -> b)
-> SimulatedTimeT m a -> SimulatedTimeT m b
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
forall a. a -> SimulatedTimeT m a
forall a b.
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a
forall a b.
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
forall a b.
SimulatedTimeT m (a -> b)
-> SimulatedTimeT m a -> SimulatedTimeT m b
forall a b c.
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (SimulatedTimeT m)
forall (m :: * -> *) a. Applicative m => a -> SimulatedTimeT m a
forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a
forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m (a -> b)
-> SimulatedTimeT m a -> SimulatedTimeT m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
<* :: SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m a
*> :: SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
liftA2 :: (a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
<*> :: SimulatedTimeT m (a -> b)
-> SimulatedTimeT m a -> SimulatedTimeT m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
SimulatedTimeT m (a -> b)
-> SimulatedTimeT m a -> SimulatedTimeT m b
pure :: a -> SimulatedTimeT m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> SimulatedTimeT m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (SimulatedTimeT m)
Applicative,
      Applicative (SimulatedTimeT m)
SimulatedTimeT m a
Applicative (SimulatedTimeT m)
-> (forall a. SimulatedTimeT m a)
-> (forall a.
    SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a)
-> (forall a. SimulatedTimeT m a -> SimulatedTimeT m [a])
-> (forall a. SimulatedTimeT m a -> SimulatedTimeT m [a])
-> Alternative (SimulatedTimeT m)
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
SimulatedTimeT m a -> SimulatedTimeT m [a]
SimulatedTimeT m a -> SimulatedTimeT m [a]
forall a. SimulatedTimeT m a
forall a. SimulatedTimeT m a -> SimulatedTimeT m [a]
forall a.
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *).
Alternative m =>
Applicative (SimulatedTimeT m)
forall (m :: * -> *) a. Alternative m => SimulatedTimeT m a
forall (m :: * -> *) a.
Alternative m =>
SimulatedTimeT m a -> SimulatedTimeT m [a]
forall (m :: * -> *) a.
Alternative m =>
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
many :: SimulatedTimeT m a -> SimulatedTimeT m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
SimulatedTimeT m a -> SimulatedTimeT m [a]
some :: SimulatedTimeT m a -> SimulatedTimeT m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
SimulatedTimeT m a -> SimulatedTimeT m [a]
<|> :: SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
empty :: SimulatedTimeT m a
$cempty :: forall (m :: * -> *) a. Alternative m => SimulatedTimeT m a
$cp1Alternative :: forall (m :: * -> *).
Alternative m =>
Applicative (SimulatedTimeT m)
Alternative,
      Applicative (SimulatedTimeT m)
a -> SimulatedTimeT m a
Applicative (SimulatedTimeT m)
-> (forall a b.
    SimulatedTimeT m a
    -> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b)
-> (forall a b.
    SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b)
-> (forall a. a -> SimulatedTimeT m a)
-> Monad (SimulatedTimeT m)
SimulatedTimeT m a
-> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
forall a. a -> SimulatedTimeT m a
forall a b.
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
forall a b.
SimulatedTimeT m a
-> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b
forall (m :: * -> *). Monad m => Applicative (SimulatedTimeT m)
forall (m :: * -> *) a. Monad m => a -> SimulatedTimeT m a
forall (m :: * -> *) a b.
Monad m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
forall (m :: * -> *) a b.
Monad m =>
SimulatedTimeT m a
-> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> SimulatedTimeT m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> SimulatedTimeT m a
>> :: SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m b
>>= :: SimulatedTimeT m a
-> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
SimulatedTimeT m a
-> (a -> SimulatedTimeT m b) -> SimulatedTimeT m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (SimulatedTimeT m)
Monad,
      Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a. IO a -> SimulatedTimeT m a)
-> MonadIO (SimulatedTimeT m)
IO a -> SimulatedTimeT m a
forall a. IO a -> SimulatedTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a. MonadIO m => IO a -> SimulatedTimeT m a
liftIO :: IO a -> SimulatedTimeT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> SimulatedTimeT m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (SimulatedTimeT m)
MonadIO,
      MonadState s,
      MonadWriter w,
      m a -> SimulatedTimeT m a
(forall (m :: * -> *) a. Monad m => m a -> SimulatedTimeT m a)
-> MonadTrans SimulatedTimeT
forall (m :: * -> *) a. Monad m => m a -> SimulatedTimeT m a
forall (t :: (* -> *) -> * -> *).
(forall (m :: * -> *) a. Monad m => m a -> t m a) -> MonadTrans t
lift :: m a -> SimulatedTimeT m a
$clift :: forall (m :: * -> *) a. Monad m => m a -> SimulatedTimeT m a
MonadTrans,
      Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a. String -> SimulatedTimeT m a)
-> MonadFail (SimulatedTimeT m)
String -> SimulatedTimeT m a
forall a. String -> SimulatedTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a. MonadFail m => String -> SimulatedTimeT m a
fail :: String -> SimulatedTimeT m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> SimulatedTimeT m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (SimulatedTimeT m)
MonadFail,
      Monad (SimulatedTimeT m)
e -> SimulatedTimeT m a
Monad (SimulatedTimeT m)
-> (forall e a. Exception e => e -> SimulatedTimeT m a)
-> MonadThrow (SimulatedTimeT m)
forall e a. Exception e => e -> SimulatedTimeT m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (SimulatedTimeT m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> SimulatedTimeT m a
throwM :: e -> SimulatedTimeT m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> SimulatedTimeT m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (SimulatedTimeT m)
MonadThrow,
      MonadThrow (SimulatedTimeT m)
MonadThrow (SimulatedTimeT m)
-> (forall e a.
    Exception e =>
    SimulatedTimeT m a
    -> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a)
-> MonadCatch (SimulatedTimeT m)
SimulatedTimeT m a
-> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a
forall e a.
Exception e =>
SimulatedTimeT m a
-> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (SimulatedTimeT m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
SimulatedTimeT m a
-> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a
catch :: SimulatedTimeT m a
-> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
SimulatedTimeT m a
-> (e -> SimulatedTimeT m a) -> SimulatedTimeT m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (SimulatedTimeT m)
MonadCatch,
      MonadError e,
      Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a b.
    ((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
    -> SimulatedTimeT m a)
-> MonadCont (SimulatedTimeT m)
((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
-> SimulatedTimeT m a
forall a b.
((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
-> SimulatedTimeT m a
forall (m :: * -> *).
Monad m -> (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
forall (m :: * -> *). MonadCont m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a b.
MonadCont m =>
((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
-> SimulatedTimeT m a
callCC :: ((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
-> SimulatedTimeT m a
$ccallCC :: forall (m :: * -> *) a b.
MonadCont m =>
((a -> SimulatedTimeT m b) -> SimulatedTimeT m a)
-> SimulatedTimeT m a
$cp1MonadCont :: forall (m :: * -> *). MonadCont m => Monad (SimulatedTimeT m)
MonadCont,
      Monad (SimulatedTimeT m)
Alternative (SimulatedTimeT m)
SimulatedTimeT m a
Alternative (SimulatedTimeT m)
-> Monad (SimulatedTimeT m)
-> (forall a. SimulatedTimeT m a)
-> (forall a.
    SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a)
-> MonadPlus (SimulatedTimeT m)
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
forall a. SimulatedTimeT m a
forall a.
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (SimulatedTimeT m)
forall (m :: * -> *). MonadPlus m => Alternative (SimulatedTimeT m)
forall (m :: * -> *) a. MonadPlus m => SimulatedTimeT m a
forall (m :: * -> *) a.
MonadPlus m =>
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
mplus :: SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
SimulatedTimeT m a -> SimulatedTimeT m a -> SimulatedTimeT m a
mzero :: SimulatedTimeT m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => SimulatedTimeT m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (SimulatedTimeT m)
$cp1MonadPlus :: forall (m :: * -> *). MonadPlus m => Alternative (SimulatedTimeT m)
MonadPlus,
      Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a. (a -> SimulatedTimeT m a) -> SimulatedTimeT m a)
-> MonadFix (SimulatedTimeT m)
(a -> SimulatedTimeT m a) -> SimulatedTimeT m a
forall a. (a -> SimulatedTimeT m a) -> SimulatedTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a.
MonadFix m =>
(a -> SimulatedTimeT m a) -> SimulatedTimeT m a
mfix :: (a -> SimulatedTimeT m a) -> SimulatedTimeT m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> SimulatedTimeT m a) -> SimulatedTimeT m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (SimulatedTimeT m)
MonadFix,
      -- MonadUnliftIO, -- gives an incomprehensible typing error
      MonadIO (SimulatedTimeT m)
MonadIO (SimulatedTimeT m)
-> (forall a. ResourceT IO a -> SimulatedTimeT m a)
-> MonadResource (SimulatedTimeT m)
ResourceT IO a -> SimulatedTimeT m a
forall a. ResourceT IO a -> SimulatedTimeT m a
forall (m :: * -> *).
MonadIO m -> (forall a. ResourceT IO a -> m a) -> MonadResource m
forall (m :: * -> *). MonadResource m => MonadIO (SimulatedTimeT m)
forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> SimulatedTimeT m a
liftResourceT :: ResourceT IO a -> SimulatedTimeT m a
$cliftResourceT :: forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> SimulatedTimeT m a
$cp1MonadResource :: forall (m :: * -> *). MonadResource m => MonadIO (SimulatedTimeT m)
MonadResource,
      Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a b.
    SimulatedTimeT m a
    -> SimulatedTimeT m b -> SimulatedTimeT m (a, b))
-> (forall a b c.
    (a -> b -> c)
    -> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c)
-> (forall a b.
    SimulatedTimeT m (a, b)
    -> (SimulatedTimeT m a, SimulatedTimeT m b))
-> MonadZip (SimulatedTimeT m)
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m (a, b)
SimulatedTimeT m (a, b) -> (SimulatedTimeT m a, SimulatedTimeT m b)
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
forall a b.
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m (a, b)
forall a b.
SimulatedTimeT m (a, b) -> (SimulatedTimeT m a, SimulatedTimeT m b)
forall a b c.
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
forall (m :: * -> *).
Monad m
-> (forall a b. m a -> m b -> m (a, b))
-> (forall a b c. (a -> b -> c) -> m a -> m b -> m c)
-> (forall a b. m (a, b) -> (m a, m b))
-> MonadZip m
forall (m :: * -> *). MonadZip m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a b.
MonadZip m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m (a, b)
forall (m :: * -> *) a b.
MonadZip m =>
SimulatedTimeT m (a, b) -> (SimulatedTimeT m a, SimulatedTimeT m b)
forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
munzip :: SimulatedTimeT m (a, b) -> (SimulatedTimeT m a, SimulatedTimeT m b)
$cmunzip :: forall (m :: * -> *) a b.
MonadZip m =>
SimulatedTimeT m (a, b) -> (SimulatedTimeT m a, SimulatedTimeT m b)
mzipWith :: (a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
$cmzipWith :: forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c)
-> SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m c
mzip :: SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m (a, b)
$cmzip :: forall (m :: * -> *) a b.
MonadZip m =>
SimulatedTimeT m a -> SimulatedTimeT m b -> SimulatedTimeT m (a, b)
$cp1MonadZip :: forall (m :: * -> *). MonadZip m => Monad (SimulatedTimeT m)
MonadZip
#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
      , Monad (SimulatedTimeT m)
Monad (SimulatedTimeT m)
-> (forall a.
    (State# (PrimState (SimulatedTimeT m))
     -> (# State# (PrimState (SimulatedTimeT m)), a #))
    -> SimulatedTimeT m a)
-> PrimMonad (SimulatedTimeT m)
(State# (PrimState (SimulatedTimeT m))
 -> (# State# (PrimState (SimulatedTimeT m)), a #))
-> SimulatedTimeT m a
forall a.
(State# (PrimState (SimulatedTimeT m))
 -> (# State# (PrimState (SimulatedTimeT m)), a #))
-> SimulatedTimeT m a
forall (m :: * -> *).
Monad m
-> (forall a.
    (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
forall (m :: * -> *). PrimMonad m => Monad (SimulatedTimeT m)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (SimulatedTimeT m))
 -> (# State# (PrimState (SimulatedTimeT m)), a #))
-> SimulatedTimeT m a
primitive :: (State# (PrimState (SimulatedTimeT m))
 -> (# State# (PrimState (SimulatedTimeT m)), a #))
-> SimulatedTimeT m a
$cprimitive :: forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (SimulatedTimeT m))
 -> (# State# (PrimState (SimulatedTimeT m)), a #))
-> SimulatedTimeT m a
$cp1PrimMonad :: forall (m :: * -> *). PrimMonad m => Monad (SimulatedTimeT m)
PrimMonad
#endif
    )

-- | Run the reader
runSimulatedTimeT :: SimulatedTimeT m a -> TimeEnv -> m a
runSimulatedTimeT :: SimulatedTimeT m a -> TimeEnv -> m a
runSimulatedTimeT = ReaderT TimeEnv m a -> TimeEnv -> m a
forall r (m :: * -> *) a. ReaderT r m a -> r -> m a
runReaderT (ReaderT TimeEnv m a -> TimeEnv -> m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> TimeEnv
-> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT

instance MonadReader r m => MonadReader r (SimulatedTimeT m) where
  ask :: SimulatedTimeT m r
ask = m r -> SimulatedTimeT m r
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift m r
forall r (m :: * -> *). MonadReader r m => m r
ask
  local :: (r -> r) -> SimulatedTimeT m a -> SimulatedTimeT m a
local r -> r
f = ReaderT TimeEnv m a -> SimulatedTimeT m a
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m a -> SimulatedTimeT m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> SimulatedTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (m a -> m a) -> ReaderT TimeEnv m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a (n :: * -> *) b r.
(m a -> n b) -> ReaderT r m a -> ReaderT r n b
mapReaderT ((r -> r) -> m a -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> r) -> m a -> m a
local r -> r
f) (ReaderT TimeEnv m a -> ReaderT TimeEnv m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> ReaderT TimeEnv m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT
  reader :: (r -> a) -> SimulatedTimeT m a
reader = m a -> SimulatedTimeT m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
lift (m a -> SimulatedTimeT m a)
-> ((r -> a) -> m a) -> (r -> a) -> SimulatedTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. (r -> a) -> m a
forall r (m :: * -> *) a. MonadReader r m => (r -> a) -> m a
reader

instance MonadIO m => MonadTime (SimulatedTimeT m) where
  getCurrentTime :: SimulatedTimeT m UTCTime
getCurrentTime = ReaderT TimeEnv m UTCTime -> SimulatedTimeT m UTCTime
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m UTCTime -> SimulatedTimeT m UTCTime)
-> ReaderT TimeEnv m UTCTime -> SimulatedTimeT m UTCTime
forall a b. (a -> b) -> a -> b
$ do
    TimeEnv
env <- ReaderT TimeEnv m TimeEnv
forall r (m :: * -> *). MonadReader r m => m r
ask
    IO UTCTime -> ReaderT TimeEnv m UTCTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO UTCTime -> ReaderT TimeEnv m UTCTime)
-> IO UTCTime -> ReaderT TimeEnv m UTCTime
forall a b. (a -> b) -> a -> b
$ TimeEnv -> IO UTCTime
getSimulatedTime TimeEnv
env

  threadDelay :: Int -> SimulatedTimeT m ()
threadDelay Int
delay = ReaderT TimeEnv m () -> SimulatedTimeT m ()
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m () -> SimulatedTimeT m ())
-> ReaderT TimeEnv m () -> SimulatedTimeT m ()
forall a b. (a -> b) -> a -> b
$ do
    TimeEnv
env <- ReaderT TimeEnv m TimeEnv
forall r (m :: * -> *). MonadReader r m => m r
ask
    IO () -> ReaderT TimeEnv m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> ReaderT TimeEnv m ()) -> IO () -> ReaderT TimeEnv m ()
forall a b. (a -> b) -> a -> b
$ TimeEnv -> Int -> IO ()
threadDelay' TimeEnv
env Int
delay

-- | Use 'TimeEnv' to control the simulated time, for instance call
-- 'Time.SimlatedTime.advance' on it to advance in simulated time.
getTimeEnv :: Monad m => SimulatedTimeT m TimeEnv
getTimeEnv :: SimulatedTimeT m TimeEnv
getTimeEnv = ReaderT TimeEnv m TimeEnv -> SimulatedTimeT m TimeEnv
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT ReaderT TimeEnv m TimeEnv
forall r (m :: * -> *). MonadReader r m => m r
ask

instance MonadUnliftIO m => MonadUnliftIO (SimulatedTimeT m) where
   withRunInIO :: ((forall a. SimulatedTimeT m a -> IO a) -> IO b)
-> SimulatedTimeT m b
withRunInIO (inner :: (forall a. SimulatedTimeT m a -> IO a) -> IO b) =
     ReaderT TimeEnv m b -> SimulatedTimeT m b
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (((forall a. ReaderT TimeEnv m a -> IO a) -> IO b)
-> ReaderT TimeEnv m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. ReaderT TimeEnv m a -> IO a
x -> (forall a. SimulatedTimeT m a -> IO a) -> IO b
inner (ReaderT TimeEnv m a -> IO a
forall a. ReaderT TimeEnv m a -> IO a
x (ReaderT TimeEnv m a -> IO a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT))) -- \x is needed to avoid some typing problems

instance MonadMask m => MonadMask (SimulatedTimeT m) where
    mask :: ((forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
 -> SimulatedTimeT m b)
-> SimulatedTimeT m b
mask (forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
-> SimulatedTimeT m b
inner = ReaderT TimeEnv m b -> SimulatedTimeT m b
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m b -> SimulatedTimeT m b)
-> ReaderT TimeEnv m b -> SimulatedTimeT m b
forall a b. (a -> b) -> a -> b
$ ((forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a)
 -> ReaderT TimeEnv m b)
-> ReaderT TimeEnv m b
forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
mask (\forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
unmask -> SimulatedTimeT m b -> ReaderT TimeEnv m b
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT (SimulatedTimeT m b -> ReaderT TimeEnv m b)
-> SimulatedTimeT m b -> ReaderT TimeEnv m b
forall a b. (a -> b) -> a -> b
$ (forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
-> SimulatedTimeT m b
inner (ReaderT TimeEnv m a -> SimulatedTimeT m a
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m a -> SimulatedTimeT m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> SimulatedTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
unmask (ReaderT TimeEnv m a -> ReaderT TimeEnv m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> ReaderT TimeEnv m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT))
    uninterruptibleMask :: ((forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
 -> SimulatedTimeT m b)
-> SimulatedTimeT m b
uninterruptibleMask (forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
-> SimulatedTimeT m b
inner = ReaderT TimeEnv m b -> SimulatedTimeT m b
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (((forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a)
 -> ReaderT TimeEnv m b)
-> ReaderT TimeEnv m b
forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask (\forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
unmask -> SimulatedTimeT m b -> ReaderT TimeEnv m b
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT (SimulatedTimeT m b -> ReaderT TimeEnv m b)
-> SimulatedTimeT m b -> ReaderT TimeEnv m b
forall a b. (a -> b) -> a -> b
$ (forall a. SimulatedTimeT m a -> SimulatedTimeT m a)
-> SimulatedTimeT m b
inner (ReaderT TimeEnv m a -> SimulatedTimeT m a
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m a -> SimulatedTimeT m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> SimulatedTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
forall a. ReaderT TimeEnv m a -> ReaderT TimeEnv m a
unmask (ReaderT TimeEnv m a -> ReaderT TimeEnv m a)
-> (SimulatedTimeT m a -> ReaderT TimeEnv m a)
-> SimulatedTimeT m a
-> ReaderT TimeEnv m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT)))
    generalBracket :: SimulatedTimeT m a
-> (a -> ExitCase b -> SimulatedTimeT m c)
-> (a -> SimulatedTimeT m b)
-> SimulatedTimeT m (b, c)
generalBracket SimulatedTimeT m a
acquire a -> ExitCase b -> SimulatedTimeT m c
release a -> SimulatedTimeT m b
inner =
      ReaderT TimeEnv m (b, c) -> SimulatedTimeT m (b, c)
forall (m :: * -> *) a. ReaderT TimeEnv m a -> SimulatedTimeT m a
SimulatedTimeT (ReaderT TimeEnv m (b, c) -> SimulatedTimeT m (b, c))
-> ReaderT TimeEnv m (b, c) -> SimulatedTimeT m (b, c)
forall a b. (a -> b) -> a -> b
$ ReaderT TimeEnv m a
-> (a -> ExitCase b -> ReaderT TimeEnv m c)
-> (a -> ReaderT TimeEnv m b)
-> ReaderT TimeEnv m (b, c)
forall (m :: * -> *) a b c.
MonadMask m =>
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c)
generalBracket (SimulatedTimeT m a -> ReaderT TimeEnv m a
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT SimulatedTimeT m a
acquire) (((ExitCase b -> SimulatedTimeT m c)
 -> ExitCase b -> ReaderT TimeEnv m c)
-> (a -> ExitCase b -> SimulatedTimeT m c)
-> a
-> ExitCase b
-> ReaderT TimeEnv m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((SimulatedTimeT m c -> ReaderT TimeEnv m c)
-> (ExitCase b -> SimulatedTimeT m c)
-> ExitCase b
-> ReaderT TimeEnv m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap SimulatedTimeT m c -> ReaderT TimeEnv m c
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT) a -> ExitCase b -> SimulatedTimeT m c
release) ((SimulatedTimeT m b -> ReaderT TimeEnv m b)
-> (a -> SimulatedTimeT m b) -> a -> ReaderT TimeEnv m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (SimulatedTimeT m b -> ReaderT TimeEnv m b
forall (m :: * -> *) a. SimulatedTimeT m a -> ReaderT TimeEnv m a
unSimulatedTimeT) a -> SimulatedTimeT m b
inner)

-- | An implementation for `MonadTime` that uses real time directly,
-- not allowing for control. Use it from code where you need to choose
-- implementation for MockTime, but don't need to control the time.
--
-- Example: use this one in the executable, while `SimulatedTimeT` is
-- used in tests that need to control time.
newtype RealTimeT m a = RealTimeT {RealTimeT m a -> m a
runRealTimeT :: m a}
  deriving
    ( a -> RealTimeT m b -> RealTimeT m a
(a -> b) -> RealTimeT m a -> RealTimeT m b
(forall a b. (a -> b) -> RealTimeT m a -> RealTimeT m b)
-> (forall a b. a -> RealTimeT m b -> RealTimeT m a)
-> Functor (RealTimeT m)
forall a b. a -> RealTimeT m b -> RealTimeT m a
forall a b. (a -> b) -> RealTimeT m a -> RealTimeT m b
forall (m :: * -> *) a b.
Functor m =>
a -> RealTimeT m b -> RealTimeT m a
forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RealTimeT m a -> RealTimeT m b
forall (f :: * -> *).
(forall a b. (a -> b) -> f a -> f b)
-> (forall a b. a -> f b -> f a) -> Functor f
<$ :: a -> RealTimeT m b -> RealTimeT m a
$c<$ :: forall (m :: * -> *) a b.
Functor m =>
a -> RealTimeT m b -> RealTimeT m a
fmap :: (a -> b) -> RealTimeT m a -> RealTimeT m b
$cfmap :: forall (m :: * -> *) a b.
Functor m =>
(a -> b) -> RealTimeT m a -> RealTimeT m b
Functor,
      Functor (RealTimeT m)
a -> RealTimeT m a
Functor (RealTimeT m)
-> (forall a. a -> RealTimeT m a)
-> (forall a b.
    RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b)
-> (forall a b c.
    (a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c)
-> (forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m b)
-> (forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m a)
-> Applicative (RealTimeT m)
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
RealTimeT m a -> RealTimeT m b -> RealTimeT m a
RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
forall a. a -> RealTimeT m a
forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m a
forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m b
forall a b. RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b
forall a b c.
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
forall (f :: * -> *).
Functor f
-> (forall a. a -> f a)
-> (forall a b. f (a -> b) -> f a -> f b)
-> (forall a b c. (a -> b -> c) -> f a -> f b -> f c)
-> (forall a b. f a -> f b -> f b)
-> (forall a b. f a -> f b -> f a)
-> Applicative f
forall (m :: * -> *). Applicative m => Functor (RealTimeT m)
forall (m :: * -> *) a. Applicative m => a -> RealTimeT m a
forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m a
forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b
forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
<* :: RealTimeT m a -> RealTimeT m b -> RealTimeT m a
$c<* :: forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m a
*> :: RealTimeT m a -> RealTimeT m b -> RealTimeT m b
$c*> :: forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
liftA2 :: (a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
$cliftA2 :: forall (m :: * -> *) a b c.
Applicative m =>
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
<*> :: RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b
$c<*> :: forall (m :: * -> *) a b.
Applicative m =>
RealTimeT m (a -> b) -> RealTimeT m a -> RealTimeT m b
pure :: a -> RealTimeT m a
$cpure :: forall (m :: * -> *) a. Applicative m => a -> RealTimeT m a
$cp1Applicative :: forall (m :: * -> *). Applicative m => Functor (RealTimeT m)
Applicative,
      Applicative (RealTimeT m)
RealTimeT m a
Applicative (RealTimeT m)
-> (forall a. RealTimeT m a)
-> (forall a. RealTimeT m a -> RealTimeT m a -> RealTimeT m a)
-> (forall a. RealTimeT m a -> RealTimeT m [a])
-> (forall a. RealTimeT m a -> RealTimeT m [a])
-> Alternative (RealTimeT m)
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
RealTimeT m a -> RealTimeT m [a]
RealTimeT m a -> RealTimeT m [a]
forall a. RealTimeT m a
forall a. RealTimeT m a -> RealTimeT m [a]
forall a. RealTimeT m a -> RealTimeT m a -> RealTimeT m a
forall (f :: * -> *).
Applicative f
-> (forall a. f a)
-> (forall a. f a -> f a -> f a)
-> (forall a. f a -> f [a])
-> (forall a. f a -> f [a])
-> Alternative f
forall (m :: * -> *). Alternative m => Applicative (RealTimeT m)
forall (m :: * -> *) a. Alternative m => RealTimeT m a
forall (m :: * -> *) a.
Alternative m =>
RealTimeT m a -> RealTimeT m [a]
forall (m :: * -> *) a.
Alternative m =>
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
many :: RealTimeT m a -> RealTimeT m [a]
$cmany :: forall (m :: * -> *) a.
Alternative m =>
RealTimeT m a -> RealTimeT m [a]
some :: RealTimeT m a -> RealTimeT m [a]
$csome :: forall (m :: * -> *) a.
Alternative m =>
RealTimeT m a -> RealTimeT m [a]
<|> :: RealTimeT m a -> RealTimeT m a -> RealTimeT m a
$c<|> :: forall (m :: * -> *) a.
Alternative m =>
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
empty :: RealTimeT m a
$cempty :: forall (m :: * -> *) a. Alternative m => RealTimeT m a
$cp1Alternative :: forall (m :: * -> *). Alternative m => Applicative (RealTimeT m)
Alternative,
      Applicative (RealTimeT m)
a -> RealTimeT m a
Applicative (RealTimeT m)
-> (forall a b.
    RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b)
-> (forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m b)
-> (forall a. a -> RealTimeT m a)
-> Monad (RealTimeT m)
RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
forall a. a -> RealTimeT m a
forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m b
forall a b. RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b
forall (m :: * -> *). Monad m => Applicative (RealTimeT m)
forall (m :: * -> *) a. Monad m => a -> RealTimeT m a
forall (m :: * -> *) a b.
Monad m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
forall (m :: * -> *) a b.
Monad m =>
RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b
forall (m :: * -> *).
Applicative m
-> (forall a b. m a -> (a -> m b) -> m b)
-> (forall a b. m a -> m b -> m b)
-> (forall a. a -> m a)
-> Monad m
return :: a -> RealTimeT m a
$creturn :: forall (m :: * -> *) a. Monad m => a -> RealTimeT m a
>> :: RealTimeT m a -> RealTimeT m b -> RealTimeT m b
$c>> :: forall (m :: * -> *) a b.
Monad m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m b
>>= :: RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b
$c>>= :: forall (m :: * -> *) a b.
Monad m =>
RealTimeT m a -> (a -> RealTimeT m b) -> RealTimeT m b
$cp1Monad :: forall (m :: * -> *). Monad m => Applicative (RealTimeT m)
Monad,
      Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a. IO a -> RealTimeT m a) -> MonadIO (RealTimeT m)
IO a -> RealTimeT m a
forall a. IO a -> RealTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. IO a -> m a) -> MonadIO m
forall (m :: * -> *). MonadIO m => Monad (RealTimeT m)
forall (m :: * -> *) a. MonadIO m => IO a -> RealTimeT m a
liftIO :: IO a -> RealTimeT m a
$cliftIO :: forall (m :: * -> *) a. MonadIO m => IO a -> RealTimeT m a
$cp1MonadIO :: forall (m :: * -> *). MonadIO m => Monad (RealTimeT m)
MonadIO,
      MonadReader s,
      MonadState s,
      MonadWriter w,
      --MonadTrans, "cannot eta-reduce the representation type enough", says ghc
      Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a. String -> RealTimeT m a) -> MonadFail (RealTimeT m)
String -> RealTimeT m a
forall a. String -> RealTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. String -> m a) -> MonadFail m
forall (m :: * -> *). MonadFail m => Monad (RealTimeT m)
forall (m :: * -> *) a. MonadFail m => String -> RealTimeT m a
fail :: String -> RealTimeT m a
$cfail :: forall (m :: * -> *) a. MonadFail m => String -> RealTimeT m a
$cp1MonadFail :: forall (m :: * -> *). MonadFail m => Monad (RealTimeT m)
MonadFail,
      Monad (RealTimeT m)
e -> RealTimeT m a
Monad (RealTimeT m)
-> (forall e a. Exception e => e -> RealTimeT m a)
-> MonadThrow (RealTimeT m)
forall e a. Exception e => e -> RealTimeT m a
forall (m :: * -> *).
Monad m -> (forall e a. Exception e => e -> m a) -> MonadThrow m
forall (m :: * -> *). MonadThrow m => Monad (RealTimeT m)
forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> RealTimeT m a
throwM :: e -> RealTimeT m a
$cthrowM :: forall (m :: * -> *) e a.
(MonadThrow m, Exception e) =>
e -> RealTimeT m a
$cp1MonadThrow :: forall (m :: * -> *). MonadThrow m => Monad (RealTimeT m)
MonadThrow,
      MonadThrow (RealTimeT m)
MonadThrow (RealTimeT m)
-> (forall e a.
    Exception e =>
    RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a)
-> MonadCatch (RealTimeT m)
RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a
forall e a.
Exception e =>
RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a
forall (m :: * -> *).
MonadThrow m
-> (forall e a. Exception e => m a -> (e -> m a) -> m a)
-> MonadCatch m
forall (m :: * -> *). MonadCatch m => MonadThrow (RealTimeT m)
forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a
catch :: RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a
$ccatch :: forall (m :: * -> *) e a.
(MonadCatch m, Exception e) =>
RealTimeT m a -> (e -> RealTimeT m a) -> RealTimeT m a
$cp1MonadCatch :: forall (m :: * -> *). MonadCatch m => MonadThrow (RealTimeT m)
MonadCatch,
      MonadError e,
      Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a b.
    ((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a)
-> MonadCont (RealTimeT m)
((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a
forall a b.
((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a
forall (m :: * -> *).
Monad m -> (forall a b. ((a -> m b) -> m a) -> m a) -> MonadCont m
forall (m :: * -> *). MonadCont m => Monad (RealTimeT m)
forall (m :: * -> *) a b.
MonadCont m =>
((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a
callCC :: ((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a
$ccallCC :: forall (m :: * -> *) a b.
MonadCont m =>
((a -> RealTimeT m b) -> RealTimeT m a) -> RealTimeT m a
$cp1MonadCont :: forall (m :: * -> *). MonadCont m => Monad (RealTimeT m)
MonadCont,
      Monad (RealTimeT m)
Alternative (RealTimeT m)
RealTimeT m a
Alternative (RealTimeT m)
-> Monad (RealTimeT m)
-> (forall a. RealTimeT m a)
-> (forall a. RealTimeT m a -> RealTimeT m a -> RealTimeT m a)
-> MonadPlus (RealTimeT m)
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
forall a. RealTimeT m a
forall a. RealTimeT m a -> RealTimeT m a -> RealTimeT m a
forall (m :: * -> *).
Alternative m
-> Monad m
-> (forall a. m a)
-> (forall a. m a -> m a -> m a)
-> MonadPlus m
forall (m :: * -> *). MonadPlus m => Monad (RealTimeT m)
forall (m :: * -> *). MonadPlus m => Alternative (RealTimeT m)
forall (m :: * -> *) a. MonadPlus m => RealTimeT m a
forall (m :: * -> *) a.
MonadPlus m =>
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
mplus :: RealTimeT m a -> RealTimeT m a -> RealTimeT m a
$cmplus :: forall (m :: * -> *) a.
MonadPlus m =>
RealTimeT m a -> RealTimeT m a -> RealTimeT m a
mzero :: RealTimeT m a
$cmzero :: forall (m :: * -> *) a. MonadPlus m => RealTimeT m a
$cp2MonadPlus :: forall (m :: * -> *). MonadPlus m => Monad (RealTimeT m)
$cp1MonadPlus :: forall (m :: * -> *). MonadPlus m => Alternative (RealTimeT m)
MonadPlus,
      Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a. (a -> RealTimeT m a) -> RealTimeT m a)
-> MonadFix (RealTimeT m)
(a -> RealTimeT m a) -> RealTimeT m a
forall a. (a -> RealTimeT m a) -> RealTimeT m a
forall (m :: * -> *).
Monad m -> (forall a. (a -> m a) -> m a) -> MonadFix m
forall (m :: * -> *). MonadFix m => Monad (RealTimeT m)
forall (m :: * -> *) a.
MonadFix m =>
(a -> RealTimeT m a) -> RealTimeT m a
mfix :: (a -> RealTimeT m a) -> RealTimeT m a
$cmfix :: forall (m :: * -> *) a.
MonadFix m =>
(a -> RealTimeT m a) -> RealTimeT m a
$cp1MonadFix :: forall (m :: * -> *). MonadFix m => Monad (RealTimeT m)
MonadFix,
      MonadIO (RealTimeT m)
MonadIO (RealTimeT m)
-> (forall a. ResourceT IO a -> RealTimeT m a)
-> MonadResource (RealTimeT m)
ResourceT IO a -> RealTimeT m a
forall a. ResourceT IO a -> RealTimeT m a
forall (m :: * -> *).
MonadIO m -> (forall a. ResourceT IO a -> m a) -> MonadResource m
forall (m :: * -> *). MonadResource m => MonadIO (RealTimeT m)
forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> RealTimeT m a
liftResourceT :: ResourceT IO a -> RealTimeT m a
$cliftResourceT :: forall (m :: * -> *) a.
MonadResource m =>
ResourceT IO a -> RealTimeT m a
$cp1MonadResource :: forall (m :: * -> *). MonadResource m => MonadIO (RealTimeT m)
MonadResource,
      Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a b.
    RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b))
-> (forall a b c.
    (a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c)
-> (forall a b.
    RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b))
-> MonadZip (RealTimeT m)
RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b)
RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b)
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
forall a b. RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b)
forall a b. RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b)
forall a b c.
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
forall (m :: * -> *).
Monad m
-> (forall a b. m a -> m b -> m (a, b))
-> (forall a b c. (a -> b -> c) -> m a -> m b -> m c)
-> (forall a b. m (a, b) -> (m a, m b))
-> MonadZip m
forall (m :: * -> *). MonadZip m => Monad (RealTimeT m)
forall (m :: * -> *) a b.
MonadZip m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b)
forall (m :: * -> *) a b.
MonadZip m =>
RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b)
forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
munzip :: RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b)
$cmunzip :: forall (m :: * -> *) a b.
MonadZip m =>
RealTimeT m (a, b) -> (RealTimeT m a, RealTimeT m b)
mzipWith :: (a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
$cmzipWith :: forall (m :: * -> *) a b c.
MonadZip m =>
(a -> b -> c) -> RealTimeT m a -> RealTimeT m b -> RealTimeT m c
mzip :: RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b)
$cmzip :: forall (m :: * -> *) a b.
MonadZip m =>
RealTimeT m a -> RealTimeT m b -> RealTimeT m (a, b)
$cp1MonadZip :: forall (m :: * -> *). MonadZip m => Monad (RealTimeT m)
MonadZip
#if MIN_VERSION_GLASGOW_HASKELL(8,2,0,0)
      , Monad (RealTimeT m)
Monad (RealTimeT m)
-> (forall a.
    (State# (PrimState (RealTimeT m))
     -> (# State# (PrimState (RealTimeT m)), a #))
    -> RealTimeT m a)
-> PrimMonad (RealTimeT m)
(State# (PrimState (RealTimeT m))
 -> (# State# (PrimState (RealTimeT m)), a #))
-> RealTimeT m a
forall a.
(State# (PrimState (RealTimeT m))
 -> (# State# (PrimState (RealTimeT m)), a #))
-> RealTimeT m a
forall (m :: * -> *).
Monad m
-> (forall a.
    (State# (PrimState m) -> (# State# (PrimState m), a #)) -> m a)
-> PrimMonad m
forall (m :: * -> *). PrimMonad m => Monad (RealTimeT m)
forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (RealTimeT m))
 -> (# State# (PrimState (RealTimeT m)), a #))
-> RealTimeT m a
primitive :: (State# (PrimState (RealTimeT m))
 -> (# State# (PrimState (RealTimeT m)), a #))
-> RealTimeT m a
$cprimitive :: forall (m :: * -> *) a.
PrimMonad m =>
(State# (PrimState (RealTimeT m))
 -> (# State# (PrimState (RealTimeT m)), a #))
-> RealTimeT m a
$cp1PrimMonad :: forall (m :: * -> *). PrimMonad m => Monad (RealTimeT m)
PrimMonad
#endif
    )

instance MonadIO m => MonadTime (RealTimeT m) where
  getCurrentTime :: RealTimeT m UTCTime
getCurrentTime = m UTCTime -> RealTimeT m UTCTime
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m UTCTime -> RealTimeT m UTCTime)
-> m UTCTime -> RealTimeT m UTCTime
forall a b. (a -> b) -> a -> b
$ IO UTCTime -> m UTCTime
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO UTCTime -> m UTCTime) -> IO UTCTime -> m UTCTime
forall a b. (a -> b) -> a -> b
$ IO UTCTime
Data.Time.getCurrentTime
  threadDelay :: Int -> RealTimeT m ()
threadDelay Int
delay = m () -> RealTimeT m ()
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m () -> RealTimeT m ()) -> m () -> RealTimeT m ()
forall a b. (a -> b) -> a -> b
$ do IO () -> m ()
forall (m :: * -> *) a. MonadIO m => IO a -> m a
liftIO (IO () -> m ()) -> IO () -> m ()
forall a b. (a -> b) -> a -> b
$ Int -> IO ()
Control.Concurrent.threadDelay Int
delay

instance MonadUnliftIO m => MonadUnliftIO (RealTimeT m) where
   withRunInIO :: ((forall a. RealTimeT m a -> IO a) -> IO b) -> RealTimeT m b
withRunInIO (inner :: (forall a. RealTimeT m a -> IO a) -> IO b) =
     m b -> RealTimeT m b
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (((forall a. m a -> IO a) -> IO b) -> m b
forall (m :: * -> *) b.
MonadUnliftIO m =>
((forall a. m a -> IO a) -> IO b) -> m b
withRunInIO (\forall a. m a -> IO a
x -> (forall a. RealTimeT m a -> IO a) -> IO b
inner (m a -> IO a
forall a. m a -> IO a
x (m a -> IO a) -> (RealTimeT m a -> m a) -> RealTimeT m a -> IO a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RealTimeT m a -> m a
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT))) -- \x is needed to avoid some typing problems

instance MonadMask m => MonadMask (RealTimeT m) where
    mask :: ((forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b)
-> RealTimeT m b
mask (forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b
inner = m b -> RealTimeT m b
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m b -> RealTimeT m b) -> m b -> RealTimeT m b
forall a b. (a -> b) -> a -> b
$ ((forall a. m a -> m a) -> m b) -> m b
forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
mask (\forall a. m a -> m a
unmask -> RealTimeT m b -> m b
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT (RealTimeT m b -> m b) -> RealTimeT m b -> m b
forall a b. (a -> b) -> a -> b
$ (forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b
inner (m a -> RealTimeT m a
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m a -> RealTimeT m a)
-> (RealTimeT m a -> m a) -> RealTimeT m a -> RealTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall a. m a -> m a
unmask (m a -> m a) -> (RealTimeT m a -> m a) -> RealTimeT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RealTimeT m a -> m a
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT))
    uninterruptibleMask :: ((forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b)
-> RealTimeT m b
uninterruptibleMask (forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b
inner = m b -> RealTimeT m b
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (((forall a. m a -> m a) -> m b) -> m b
forall (m :: * -> *) b.
MonadMask m =>
((forall a. m a -> m a) -> m b) -> m b
uninterruptibleMask (\forall a. m a -> m a
unmask -> RealTimeT m b -> m b
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT (RealTimeT m b -> m b) -> RealTimeT m b -> m b
forall a b. (a -> b) -> a -> b
$ (forall a. RealTimeT m a -> RealTimeT m a) -> RealTimeT m b
inner (m a -> RealTimeT m a
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m a -> RealTimeT m a)
-> (RealTimeT m a -> m a) -> RealTimeT m a -> RealTimeT m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. m a -> m a
forall a. m a -> m a
unmask (m a -> m a) -> (RealTimeT m a -> m a) -> RealTimeT m a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RealTimeT m a -> m a
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT)))
    generalBracket :: RealTimeT m a
-> (a -> ExitCase b -> RealTimeT m c)
-> (a -> RealTimeT m b)
-> RealTimeT m (b, c)
generalBracket RealTimeT m a
acquire a -> ExitCase b -> RealTimeT m c
release a -> RealTimeT m b
inner =
      m (b, c) -> RealTimeT m (b, c)
forall k (m :: k -> *) (a :: k). m a -> RealTimeT m a
RealTimeT (m (b, c) -> RealTimeT m (b, c)) -> m (b, c) -> RealTimeT m (b, c)
forall a b. (a -> b) -> a -> b
$ m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c)
forall (m :: * -> *) a b c.
MonadMask m =>
m a -> (a -> ExitCase b -> m c) -> (a -> m b) -> m (b, c)
generalBracket (RealTimeT m a -> m a
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT RealTimeT m a
acquire) (((ExitCase b -> RealTimeT m c) -> ExitCase b -> m c)
-> (a -> ExitCase b -> RealTimeT m c) -> a -> ExitCase b -> m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap ((RealTimeT m c -> m c)
-> (ExitCase b -> RealTimeT m c) -> ExitCase b -> m c
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap RealTimeT m c -> m c
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT) a -> ExitCase b -> RealTimeT m c
release) ((RealTimeT m b -> m b) -> (a -> RealTimeT m b) -> a -> m b
forall (f :: * -> *) a b. Functor f => (a -> b) -> f a -> f b
fmap (RealTimeT m b -> m b
forall k (m :: k -> *) (a :: k). RealTimeT m a -> m a
runRealTimeT) a -> RealTimeT m b
inner)