commit b29620e1f8444b8582b1584964380354dc704aae
parent a295965f0f5c44fd8801c0abc696e13cc9aba30e
Author: Jared Tobin <jared@jtobin.ca>
Date: Fri, 12 Feb 2016 18:42:28 +1300
Merge pull request #2 from sacundim/master
Add `MonadIO` and `PrimMonad` instances for `Prob`
Diffstat:
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