random-fu-0.1.4: Random number generation

Data.Random.Source

Synopsis

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).

Methods

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.

class Monad m => RandomSource m s whereSource

A source of entropy which can be used in the given monad.

See also MonadRandom.

Methods

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.

data Prim a whereSource

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.

Instances