Safe Haskell | None |
---|
- data Prim a where
- PrimWord8 :: Prim Word8
- PrimWord16 :: Prim Word16
- PrimWord32 :: Prim Word32
- PrimWord64 :: Prim Word64
- PrimDouble :: Prim Double
- PrimNByteInteger :: !Int -> Prim Integer
- class Monad m => MonadRandom m where
- getRandomPrim :: Prim t -> m t
- getRandomWord8 :: m Word8
- getRandomWord16 :: m Word16
- getRandomWord32 :: m Word32
- getRandomWord64 :: m Word64
- getRandomDouble :: m Double
- getRandomNByteInteger :: MonadRandom m => Int -> m Integer
- class Monad m => RandomSource m s where
- getRandomPrimFrom :: s -> Prim t -> m t
- getRandomWord8From :: s -> m Word8
- getRandomWord16From :: s -> m Word16
- getRandomWord32From :: s -> m Word32
- getRandomWord64From :: s -> m Word64
- getRandomDoubleFrom :: s -> m Double
- getRandomNByteIntegerFrom :: s -> Int -> m Integer
- newtype GetPrim m = GetPrim (forall t. Prim t -> m t)
Documentation
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 those requests. The functions in
Data.Random.Source.Internal.TH extend incomplete entropy-source definitions
to complete ones, 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 PrimBytes :: !Int -> Prim ByteString
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 |
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.
Minimum implementation is either the internal getRandomPrim
or all
other functions. Additionally, this class's interface is subject to
extension at any time, so it is very, very strongly recommended that
the monadRandom
Template Haskell function be used to implement this
function rather than directly implementing it. That function takes care
of choosing default implementations for any missing functions; as long as
at least one function is implemented, it will derive sensible
implementations of all others.
To use monadRandom
, just wrap your instance declaration as follows (and
enable the TemplateHaskell and GADTs language extensions):
$(monadRandom [d| instance MonadRandom FooM where getRandomDouble = return pi getRandomWord16 = return 4 {- etc... -} |])
getRandomPrim :: Prim t -> m tSource
Generate a random value corresponding to the specified primitive.
This is an internal interface; use at your own risk. It may change or disappear at any time.
getRandomWord8 :: m Word8Source
Generate a uniformly distributed random Word8
getRandomWord16 :: m Word16Source
Generate a uniformly distributed random Word16
getRandomWord32 :: m Word32Source
Generate a uniformly distributed random Word32
getRandomWord64 :: m Word64Source
Generate a uniformly distributed random Word64
getRandomDouble :: m DoubleSource
Generate a uniformly distributed random Double
in the range 0 <= U < 1
getRandomNByteInteger :: MonadRandom m => Int -> m IntegerSource
Generate a uniformly distributed random Integer
in the range 0 <= U < 256^n
MonadRandom IO | |
Monad m0 => MonadRandom (StateT PureMT m0) | |
Monad m => MonadRandom (StateT StdGen m) | |
Monad m0 => MonadRandom (StateT PureMT m0) | |
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
.
Minimum implementation is either the internal getRandomPrimFrom
or all
other functions. Additionally, this class's interface is subject to
extension at any time, so it is very, very strongly recommended that
the randomSource
Template Haskell function be used to implement this
function rather than directly implementing it. That function takes care
of choosing default implementations for any missing functions; as long as
at least one function is implemented, it will derive sensible
implementations of all others.
To use randomSource
, just wrap your instance declaration as follows (and
enable the TemplateHaskell, MultiParamTypeClasses and GADTs language
extensions, as well as any others required by your instances, such as
FlexibleInstances):
$(randomSource [d| instance RandomSource FooM Bar where {- at least one RandomSource function... -} |])
getRandomPrimFrom :: s -> Prim t -> m tSource
Generate a random value corresponding to the specified primitive.
This is an internal interface; use at your own risk. It may change or disappear at any time.
getRandomWord8From :: s -> m Word8Source
Generate a uniformly distributed random Word8
getRandomWord16From :: s -> m Word16Source
Generate a uniformly distributed random Word16
getRandomWord32From :: s -> m Word32Source
Generate a uniformly distributed random Word32
getRandomWord64From :: s -> m Word64Source
Generate a uniformly distributed random Word64
getRandomDoubleFrom :: s -> m DoubleSource
Generate a uniformly distributed random Double
in the range 0 <= U < 1
getRandomNByteIntegerFrom :: s -> Int -> m IntegerSource
Generate a uniformly distributed random Integer
in the range 0 <= U < 256^n
RandomSource IO DevRandom | |
MonadRandom m => RandomSource m StdRandom | |
RandomSource IO (Gen RealWorld) | |
Monad m => RandomSource m (GetPrim m) | |
(Monad m, ModifyRef (IORef StdGen) m StdGen) => RandomSource m (IORef StdGen) | |
MonadIO m0 => RandomSource m0 (IORef PureMT) | |
Monad m0 => RandomSource m0 (m0 Word8) | |
Monad m0 => RandomSource m0 (m0 Word16) | |
Monad m0 => RandomSource m0 (m0 Word32) | |
Monad m0 => RandomSource m0 (m0 Word64) | |
Monad m0 => RandomSource m0 (m0 Double) | |
(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 m10, ModifyRef (Ref m20 PureMT) m10 PureMT) => RandomSource m10 (Ref m20 PureMT) | |
(Monad m0, ModifyRef (STRef s0 PureMT) m0 PureMT) => RandomSource m0 (STRef s0 PureMT) | |
RandomSource (ST s0) (Gen s0) |
This type provides a way to define a RandomSource
for a monad without actually
having to declare an instance.
Monad m => RandomSource m (GetPrim m) |