freer-simple-random-0.1.0.0: Random number generators using freer-simple

Copyright(c) Ben Weitzman 2018
LicenseMIT
Maintainerben@costarastrolgoy.com
Stabilityexperimental
PortabilityPOSIX
Safe HaskellNone
LanguageHaskell2010

Control.Monad.Freer.Random

Description

 
Synopsis

Documentation

data Random typs a Source #

The Random effect generates a random value for you. It is parametrized by the set of values (typs) that it generates. The Random effect needs to come at the head of the effect list in order to make type in order to make type inference of the set of types possible.

random :: forall a typs r p. (Random a, FindInList a typs) => Eff (Random typs ': r) a Source #

Generate a single random value

randomR :: forall a typs r p. (Random a, FindInList a typs) => (a, a) -> Eff (Random typs ': r) a Source #

Generate a single random value in a range

runRandom :: forall t r a. Member IO r => Eff (Random t ': r) a -> Eff r a Source #

Use the IO effect to handle generation of random values

knownRandom :: forall typ a r v. a -> Eff (Random (a ': typ) ': r) v -> Eff (Random typ ': r) v Source #

Use a single given value as the "random" value. The given value is always used, even if it's outside the range given to randomR

runRandomWithSeed :: forall typ r v. Int -> Eff (Random typ ': r) v -> Eff r v Source #

Use a seed + a PRNG to handle generation of random values.

silentRandom :: Eff (Random '[] ': r) v -> Eff r v Source #

Eliminate a Random effect that doesn't generate any values

class FindInList a as Source #

Find a type inside of a type level list. Used to write code that generates multiple types of random values that are polymorphic over the set of all random values that are generated.

getARandomNumber :: (FindInList Int typs) => Eff (Random typs ': r) Int
getARandomNumber = random

getARandomBool :: (FindInList Bool typs) => Eff (Random typs ': r) Bool
getARandomBool = random

getABoolAndInt :: (FindInList Bool typs, FindInList Int typs) => Eff (Random typs ': r) Int
getABoolAndInt = do
  rInt <- getARandomNumber
  rBool <- getARandomBool
  if rBool
    then return rInt
    else return $ rInt + 1

Minimal complete definition

find

Instances
FindInList a as => FindInList a (b ': as) Source # 
Instance details

Defined in Control.Monad.Freer.Random

Methods

find :: Elem a (b ': as)

FindInList a (a ': as) Source # 
Instance details

Defined in Control.Monad.Freer.Random

Methods

find :: Elem a (a ': as)