{-# 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 :: m a -> t m a
lift = m a -> t m a
forall (t :: (* -> *) -> * -> *) (m :: * -> *) a.
(MonadTrans t, Monad m) =>
m a -> t m a
T.lift
instance Lift m m where
lift :: m a -> m a
lift = m a -> m a
forall a. a -> a
id
instance Monad m => Lift T.Identity m where
lift :: Identity a -> m a
lift = a -> m a
forall (m :: * -> *) a. Monad m => a -> m a
return (a -> m a) -> (Identity a -> a) -> Identity a -> m a
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Identity a -> a
forall a. Identity a -> a
T.runIdentity
instance Lift (RVarT T.Identity) (RVarT m) where
lift :: RVarT Identity a -> RVarT m a
lift RVarT Identity a
x = RVarT Identity a -> RGen -> RVarT m a
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 :: Identity a -> t Identity a
lift = Identity a -> t Identity a
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