{-# LANGUAGE MultiParamTypeClasses, FlexibleInstances, IncoherentInstances, CPP #-}
module Data.Random.Lift where
import Data.RVar
import qualified Data.Functor.Identity as T
import qualified Control.Monad.Trans.Class as T
#ifndef MTL2
import qualified Control.Monad.Identity as MTL
#endif
class Lift m n where
lift :: m a -> n a
instance (Monad m, T.MonadTrans t) => Lift m (t m) where
lift :: forall a. m a -> t m a
lift = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
T.lift
instance Lift m m where
lift :: forall a. m a -> m a
lift = forall a. a -> a
id
instance Monad m => Lift T.Identity m where
lift :: forall a. Identity a -> m a
lift = forall (m :: * -> *) a. Monad m => a -> m a
return forall b c a. (b -> c) -> (a -> b) -> a -> c
. forall a. Identity a -> a
T.runIdentity
instance Lift (RVarT T.Identity) (RVarT m) where
lift :: forall a. RVarT Identity a -> RVarT m a
lift RVarT Identity a
x = forall g (m :: * -> *) a. StatefulGen g m => RVar a -> g -> m a
runRVar RVarT Identity a
x RGen
RGen
instance T.MonadTrans t => Lift T.Identity (t T.Identity) where
lift :: forall a. Identity a -> t Identity a
lift = forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
T.lift
#ifndef MTL2
instance Monad m => Lift MTL.Identity m where
lift = return . MTL.runIdentity
instance Lift (RVarT MTL.Identity) (RVarT m) where
lift x = runRVarTWith (return . MTL.runIdentity) x RGen
instance T.MonadTrans t => Lift MTL.Identity (t MTL.Identity) where
lift = T.lift
#endif