- class Monad m => MonadRandom m where
- getRandomPrim :: Prim t -> m t
- class Monad m => RandomSource m s where
- getRandomPrimFrom :: s -> Prim t -> m t
- data Prim a where
- PrimWord8 :: Prim Word8
- PrimWord16 :: Prim Word16
- PrimWord32 :: Prim Word32
- PrimWord64 :: Prim Word64
- PrimDouble :: Prim Double
- PrimNByteInteger :: !Int -> Prim Integer
Documentation
class Monad m => MonadRandom m whereSource
A typeclass for monads with a chosen source of entropy. For example,
RVar
is such a monad - the source from which it is (eventually) sampled
is the only source from which a random variable is permitted to draw, so
when directly requesting entropy for a random variable these functions
are used.
Occasionally one might want a RandomSource
specifying the MonadRandom
instance (for example, when using runRVar
). For those cases,
Data.Random.Source.Std.StdRandom
provides a RandomSource
that
maps to the MonadRandom
instance.
For example, State StdGen
has a MonadRandom
instance, so to run an
RVar
(called x
in this example) in this monad one could write
runRVar x StdRandom
(or more concisely with the sample
function: sample x
).
getRandomPrim :: Prim t -> m tSource
Generate a random value corresponding to the specified primitive.
The Prim
type has many variants, and is also somewhat unstable.
getPrimWhere
is a useful function for abstracting over the type,
semi-automatically extending a partial implementation to the full
Prim
type.
MonadRandom (RVarT n) | |
Monad m => MonadRandom (StateT PureMT m) | |
Monad m => MonadRandom (StateT StdGen m) | |
Monad m => MonadRandom (StateT PureMT m) | |
Monad m => MonadRandom (StateT StdGen m) |
class Monad m => RandomSource m s whereSource
A source of entropy which can be used in the given monad.
See also MonadRandom
.
getRandomPrimFrom :: s -> Prim t -> m tSource
Generate a random value corresponding to the specified primitive.
The Prim
type has many variants, and is also somewhat unstable.
getPrimWhere
is a useful function for abstracting over the type,
semi-automatically extending a partial implementation to the full
Prim
type.
RandomSource IO DevRandom | |
MonadRandom m => RandomSource m StdRandom | |
RandomSource IO (Gen RealWorld) | |
Monad m => RandomSource m (m Double) | |
Monad m => RandomSource m (m Word64) | |
Monad m => RandomSource m (m Word32) | |
Monad m => RandomSource m (m Word16) | |
Monad m => RandomSource m (m Word8) | |
(Monad m, ModifyRef (IORef StdGen) m StdGen) => RandomSource m (IORef StdGen) | |
(Monad m, ModifyRef (IORef PureMT) m PureMT) => RandomSource m (IORef PureMT) | |
(Monad m, ModifyRef (STRef s StdGen) m StdGen) => RandomSource m (STRef s StdGen) | |
(Monad m1, ModifyRef (Ref m2 StdGen) m1 StdGen) => RandomSource m1 (Ref m2 StdGen) | |
(Monad m, ModifyRef (STRef s PureMT) m PureMT) => RandomSource m (STRef s PureMT) | |
(Monad m1, ModifyRef (Ref m2 PureMT) m1 PureMT) => RandomSource m1 (Ref m2 PureMT) | |
RandomSource (ST s) (Gen s) |
A Prompt
GADT describing a request for a primitive random variate.
Random variable definitions will request their entropy via these prompts,
and entropy sources will satisfy some or all of them. The decomposePrimWhere
function extends an entropy source's incomplete definition to a complete
definition, essentially defining a very flexible implementation-defaulting
system.
Some possible future additions: PrimFloat :: Prim Float PrimInt :: Prim Int PrimPair :: Prim a -> Prim b -> Prim (a :*: b) PrimNormal :: Prim Double PrimChoice :: [(Double :*: a)] -> Prim a
Unfortunately, I cannot get Haddock to accept my comments about the data constructors, but hopefully they should be reasonably self-explanatory.
PrimWord8 :: Prim Word8 | |
PrimWord16 :: Prim Word16 | |
PrimWord32 :: Prim Word32 | |
PrimWord64 :: Prim Word64 | |
PrimDouble :: Prim Double | |
PrimNByteInteger :: !Int -> Prim Integer |