Safe Haskell | None |
---|---|
Language | Haskell2010 |
Polysemy "random-fu" effect.
This can be run in a few ways:
1. Directly in IO
2. Using any RandomSource
from "random-fu"
3. In IO
, using a given PureMT
source.
(IO
is used to put the source in an IORef
)
This module also contains the type-class instances to enable "absorbing" MonadRandom, ala Polysemy.MTL. See the tests for MTL or RandomFu for examples of that in use.
Synopsis
- data RandomFu m r where
- SampleRVar :: RVar t -> RandomFu m t
- GetRandomPrim :: Prim t -> RandomFu m t
- sampleRVar :: forall r r. Member RandomFu r => RVar r -> Sem r r
- getRandomPrim :: forall r r. Member RandomFu r => Prim r -> Sem r r
- sampleDist :: (Member RandomFu r, Distribution d t) => d t -> Sem r t
- runRandomSource :: forall s r a. RandomSource (Sem r) s => s -> Sem (RandomFu ': r) a -> Sem r a
- runRandomIO :: forall r a. MonadIO (Sem r) => Sem (RandomFu ': r) a -> Sem r a
- runRandomIOPureMT :: MonadIO (Sem r) => PureMT -> Sem (RandomFu ': r) a -> Sem r a
- absorbMonadRandom :: Member RandomFu r => (MonadRandom (Sem r) => Sem r a) -> Sem r a
Effect
data RandomFu m r where Source #
An effect capable of sampling from a "random-fu" RVar or generating a
single random-variate of any type, t
with a
Data.Random.Prim t
constructor, currently one of Word8
, Word16
,
Word32
, Word64
, Double
or N-byte integer.
SampleRVar :: RVar t -> RandomFu m t | |
GetRandomPrim :: Prim t -> RandomFu m t |
Instances
type DefiningModule (RandomFu :: k -> Type -> Type) Source # | |
Defined in Polysemy.RandomFu |
Actions
sampleDist :: (Member RandomFu r, Distribution d t) => d t -> Sem r t Source #
use the RandomFu
effect to sample from a "random-fu" Distribution
.
Interpretations
runRandomSource :: forall s r a. RandomSource (Sem r) s => s -> Sem (RandomFu ': r) a -> Sem r a Source #
Run a Random
effect using a given RandomSource
runRandomIO :: forall r a. MonadIO (Sem r) => Sem (RandomFu ': r) a -> Sem r a Source #
Run a Random
effect by using the default "random-fu" IO
source
Constraint absorber
absorbMonadRandom :: Member RandomFu r => (MonadRandom (Sem r) => Sem r a) -> Sem r a Source #
Absorb an MonadRandom
constraint.
That is, use a Member RandomFu r
constraint to satisfy the MonadRandom
constraint in a (forall m. MonadRandom m => m a), returning a
Sem r a@.
See MTL
for details.
Orphan instances
ReifiableConstraint1 MonadRandom Source # | |
data Dict1 MonadRandom m :: Type Source # reifiedInstance :: Monad m => Reifies s (Dict1 MonadRandom m) :- MonadRandom (ConstrainedAction MonadRandom m s) Source # | |
Member (RandomFu :: (Type -> Type) -> Type -> Type) r => IsCanonicalEffect MonadRandom r Source # | |
canonicalDictionary :: Dict1 MonadRandom (Sem r) Source # | |
(Monad m, Reifies s' (Dict1 MonadRandom m)) => MonadRandom (ConstrainedAction MonadRandom m s') Source # | |
getRandomPrim :: Prim t -> ConstrainedAction MonadRandom m s' t # getRandomWord8 :: ConstrainedAction MonadRandom m s' Word8 # getRandomWord16 :: ConstrainedAction MonadRandom m s' Word16 # getRandomWord32 :: ConstrainedAction MonadRandom m s' Word32 # getRandomWord64 :: ConstrainedAction MonadRandom m s' Word64 # getRandomDouble :: ConstrainedAction MonadRandom m s' Double # getRandomNByteInteger :: Int -> ConstrainedAction MonadRandom m s' Integer # |