mwc-probability

Sampling function-based probability distributions.
Log | Files | Refs | README | LICENSE

commit 4a77af08984f9ab99faccb33bd3a356668e20483
parent a295965f0f5c44fd8801c0abc696e13cc9aba30e
Author: Luis Casillas <luis.casillas@progressfin.com>
Date:   Thu, 11 Feb 2016 12:45:14 -0800

Add isntances for `MonadIO` and `PrimMonad`.

Diffstat:
Msrc/System/Random/MWC/Probability.hs | 10++++++++++
1 file changed, 10 insertions(+), 0 deletions(-)

diff --git a/src/System/Random/MWC/Probability.hs b/src/System/Random/MWC/Probability.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE TypeFamilies #-} {-# OPTIONS_GHC -Wall #-} -- | @@ -73,6 +74,7 @@ module System.Random.MWC.Probability ( import Control.Applicative import Control.Monad import Control.Monad.Primitive +import Control.Monad.IO.Class import Control.Monad.Trans.Class import Data.List (findIndex) import System.Random.MWC as MWC hiding (uniform, uniformR) @@ -120,6 +122,14 @@ instance Monad m => Monad (Prob m) where instance MonadTrans Prob where lift m = Prob $ const m +instance MonadIO m => MonadIO (Prob m) where + liftIO m = Prob $ const (liftIO m) + +instance PrimMonad m => PrimMonad (Prob m) where + type PrimState (Prob m) = PrimState m + primitive = lift . primitive + {-# INLINE primitive #-} + -- | The uniform distribution. uniform :: (PrimMonad m, Variate a) => Prob m a uniform = Prob QMWC.uniform