packages feed

MonadRandom 0.1.3 → 0.1.4

raw patch · 2 files changed

+20/−15 lines, 2 filesdep ~basenew-uploaderPVP ok

version bump matches the API change (PVP)

Dependency ranges changed: base

API changes (from Hackage documentation)

+ Control.Monad.Random: instance (Monad m) => Applicative (RandT g m)
+ Control.Monad.Random: instance Applicative (Rand g)

Files

Control/Monad/Random.hs view
@@ -1,7 +1,7 @@ {-# LANGUAGE MultiParamTypeClasses #-} {-# LANGUAGE FlexibleInstances, UndecidableInstances #-} {-# LANGUAGE GeneralizedNewtypeDeriving #-}- + {- | Copyright    : 2006-2007 Cale Gibbard, Russell O'Connor, Dan Doel, Remi Turk, Eric Kidd. License      : OtherLicense@@ -38,7 +38,7 @@     -- * Example     -- $RandExample     ) where- + import System.Random import Control.Monad() import Control.Monad.Identity@@ -48,18 +48,23 @@ import Control.Monad.Trans() import Control.Monad.Writer import Control.Arrow- +import Control.Applicative+ -- | A monad transformer which adds a random number generator to an -- existing monad. newtype (RandomGen g) => RandT g m a = RandT (StateT g m a)     deriving (Functor, Monad, MonadTrans, MonadIO) +instance (Monad m) => Applicative (RandT g m) where+  pure = return+  (<*>) = ap+ liftState :: (MonadState s m) => (s -> (a,s)) -> m a liftState t = do v <- get                  let (x, v') = t v                  put v'                  return x- + instance (Monad m, RandomGen g) => MonadRandom (RandT g m) where     getRandom = RandT . liftState $ random     getRandoms = RandT . liftState $ first randoms . split@@ -75,27 +80,27 @@ -- updated version of @g@. evalRandT :: (Monad m, RandomGen g) => RandT g m a -> g -> m a evalRandT (RandT x) g = evalStateT x g- + -- | Run a RandT computation using the generator @g@, returning the result and -- the updated generator. runRandT  :: (Monad m, RandomGen g) => RandT g m a -> g -> m (a, g) runRandT (RandT x) g = runStateT x g- + -- | A basic random monad. newtype Rand g a = Rand (RandT g Identity a)-    deriving (Functor, Monad, MonadRandom, MonadSplit g)- +    deriving (Functor, Applicative, Monad, MonadRandom, MonadSplit g)+ -- | Evaluate a random computation using the generator @g@.  Note that the -- generator @g@ is not returned, so there's no way to recover the -- updated version of @g@. evalRand :: (RandomGen g) => Rand g a -> g -> a evalRand (Rand x) g = runIdentity (evalRandT x g)- + -- | Run a random computation using the generator @g@, returning the result -- and the updated generator. runRand :: (RandomGen g) => Rand g a -> g -> (a, g) runRand (Rand x) g = runIdentity (runRandT x g)- + -- | Evaluate a random computation in the IO monad, using the random number -- generator supplied by 'System.Random.getStdRandom'. evalRandIO :: Rand StdGen a -> IO a@@ -125,7 +130,7 @@     getRandomR = lift . getRandomR     getRandoms = lift getRandoms     getRandomRs = lift . getRandomRs- + instance (MonadRandom m) => MonadRandom (ReaderT r m) where     getRandom = lift getRandom     getRandomR = lift . getRandomR@@ -144,11 +149,11 @@ instance (MonadState s m, RandomGen g) => MonadState s (RandT g m) where     get = lift get     put = lift . put- + instance (MonadReader r m, RandomGen g) => MonadReader r (RandT g m) where     ask = lift ask     local f (RandT m) = RandT $ local f m- + instance (MonadWriter w m, RandomGen g, Monoid w) => MonadWriter w (RandT g m) where     tell = lift . tell     listen (RandT m) = RandT $ listen m
MonadRandom.cabal view
@@ -1,6 +1,6 @@ Name:                MonadRandom Build-type:          Simple-Version:             0.1.3+Version:             0.1.4 Synopsis:            Random-number generation monad. Description:         Support for computations which consume random values. License:             OtherLicense@@ -9,5 +9,5 @@ Author:              Cale Gibbard and others Maintainer:          Eric Kidd <haskell@randomhacks.net> Stability:           experimental-Build-Depends:       base, mtl, random+Build-Depends:       base >=2 && < 5, mtl, random Exposed-modules:     Control.Monad.Random.Class, Control.Monad.Random