generic-random-0.5.0.0: Generic random generators

Safe HaskellNone
LanguageHaskell2010

Generic.Random.Internal.Generic

Contents

Synopsis

Random generators

genericArbitrary Source #

Arguments

:: (Generic a, GA Unsized (Rep a)) 
=> Weights a

List of weights for every constructor

-> Gen a 

Pick a constructor with a given distribution, and fill its fields recursively.

genericArbitrary' Source #

Arguments

:: (Generic a, GA (Sized n) (Rep a)) 
=> n 
-> Weights a

List of weights for every constructor

-> Gen a 

Like genericArbitrary', with decreasing size to ensure termination for recursive types, looking for base cases once the size reaches 0.

genericArbitraryU0 :: forall n a. (Generic a, GA (Sized Z) (Rep a), UniformWeight (Weights_ (Rep a))) => Gen a Source #

Shorthand for genericArbitrary' Z uniform, using nullary constructors as the base cases.

genericArbitraryU1 :: forall n a. (Generic a, GA (Sized (S Z)) (Rep a), UniformWeight (Weights_ (Rep a))) => Gen a Source #

Shorthand for genericArbitrary' (S Z) uniform, using nullary constructors and constructors whose fields are all nullary as base cases.

Internal

type family Weights_ (f :: * -> *) :: * where ... Source #

Equations

Weights_ (f :+: g) = Weights_ f :| Weights_ g 
Weights_ (M1 D _c f) = Weights_ f 
Weights_ (M1 C (MetaCons c _i _j) _f) = L c 

data a :| b Source #

Constructors

N a Int b 

Instances

(UniformWeight a, UniformWeight b) => UniformWeight ((:|) a b) Source # 

Methods

uniformWeight :: (a :| b, Int) Source #

WeightBuilder a => WeightBuilder ((:|) a b) Source # 

Associated Types

type Prec ((:|) a b) r :: * Source #

Methods

(%) :: W (First (a :| b)) -> Prec (a :| b) r -> (a :| b, Int, r) Source #

type Prec ((:|) a b) r Source # 
type Prec ((:|) a b) r = Prec a (b, Int, r)

data L c Source #

Constructors

L 

Instances

UniformWeight (L c) Source # 

Methods

uniformWeight :: (L c, Int) Source #

WeightBuilder (L c) Source # 

Associated Types

type Prec (L c) r :: * Source #

Methods

(%) :: W (First (L c)) -> Prec (L c) r -> (L c, Int, r) Source #

type Prec (L c) r Source # 
type Prec (L c) r = r

data Weights a Source #

Trees of weights assigned to constructors of type a, rescaled to obtain a probability distribution.

Two ways of constructing them.

weights (x1 % x2 % ... % xn % ()) :: Weights a
uniform :: Weights a

Using weights, there must be exactly as many weights as there are constructors.

uniform is equivalent to weights (1 % ... % 1 % ()) (automatically fills out the right number of 1s).

Constructors

Weights (Weights_ (Rep a)) Int 

newtype W c Source #

Type of a single weight, tagged with the name of the associated constructor for additional compile-time checking.

weights ((9 :: W "Leaf") % (8 :: W "Node") % ())

Constructors

W Int 

Instances

Num (W c) Source # 

Methods

(+) :: W c -> W c -> W c #

(-) :: W c -> W c -> W c #

(*) :: W c -> W c -> W c #

negate :: W c -> W c #

abs :: W c -> W c #

signum :: W c -> W c #

fromInteger :: Integer -> W c #

weights :: (Weights_ (Rep a), Int, ()) -> Weights a Source #

A smart constructor to specify a custom distribution.

uniform :: UniformWeight (Weights_ (Rep a)) => Weights a Source #

Uniform distribution.

type family First a :: Symbol where ... Source #

Equations

First (a :| _b) = First a 
First (L c) = c 

class WeightBuilder a where Source #

Minimal complete definition

(%)

Associated Types

type Prec a r Source #

Methods

(%) :: W (First a) -> Prec a r -> (a, Int, r) infixr 1 Source #

A binary constructor for building up trees of weights.

Instances

WeightBuilder () Source # 

Associated Types

type Prec () r :: * Source #

Methods

(%) :: W (First ()) -> Prec () r -> ((), Int, r) Source #

WeightBuilder (L c) Source # 

Associated Types

type Prec (L c) r :: * Source #

Methods

(%) :: W (First (L c)) -> Prec (L c) r -> (L c, Int, r) Source #

WeightBuilder a => WeightBuilder ((:|) a b) Source # 

Associated Types

type Prec ((:|) a b) r :: * Source #

Methods

(%) :: W (First (a :| b)) -> Prec (a :| b) r -> (a :| b, Int, r) Source #

class UniformWeight a where Source #

Minimal complete definition

uniformWeight

Methods

uniformWeight :: (a, Int) Source #

Instances

newtype Gen' sized a Source #

Constructors

Gen' 

Fields

Instances

Monad (Gen' sized) Source # 

Methods

(>>=) :: Gen' sized a -> (a -> Gen' sized b) -> Gen' sized b #

(>>) :: Gen' sized a -> Gen' sized b -> Gen' sized b #

return :: a -> Gen' sized a #

fail :: String -> Gen' sized a #

Functor (Gen' sized) Source # 

Methods

fmap :: (a -> b) -> Gen' sized a -> Gen' sized b #

(<$) :: a -> Gen' sized b -> Gen' sized a #

Applicative (Gen' sized) Source # 

Methods

pure :: a -> Gen' sized a #

(<*>) :: Gen' sized (a -> b) -> Gen' sized a -> Gen' sized b #

(*>) :: Gen' sized a -> Gen' sized b -> Gen' sized b #

(<*) :: Gen' sized a -> Gen' sized b -> Gen' sized a #

data Sized n Source #

Instances

(GASum (Sized n) f, GASum (Sized n) g, BaseCases n f, BaseCases n g) => GA (Sized n) ((:+:) f g) Source # 

Methods

ga :: Weights_ (f :+: g) -> Int -> Gen' (Sized n) ((f :+: g) p) Source #

(GAProduct f, KnownNat (Arity f)) => GA (Sized n) (M1 C c f) Source # 

Methods

ga :: Weights_ (M1 C c f) -> Int -> Gen' (Sized n) (M1 C c f p) Source #

data Unsized Source #

Instances

(GASum Unsized f, GASum Unsized g) => GA Unsized ((:+:) f g) Source # 

Methods

ga :: Weights_ (f :+: g) -> Int -> Gen' Unsized ((f :+: g) p) Source #

GAProduct f => GA Unsized (M1 C c f) Source # 

Methods

ga :: Weights_ (M1 C c f) -> Int -> Gen' Unsized (M1 C c f p) Source #

sized' :: (Int -> Gen' sized a) -> Gen' sized a Source #

class GA sized f where Source #

Generic Arbitrary

Minimal complete definition

ga

Methods

ga :: Weights_ f -> Int -> Gen' sized (f p) Source #

Instances

(GASum Unsized f, GASum Unsized g) => GA Unsized ((:+:) f g) Source # 

Methods

ga :: Weights_ (f :+: g) -> Int -> Gen' Unsized ((f :+: g) p) Source #

GA sized f => GA sized (M1 D c f) Source # 

Methods

ga :: Weights_ (M1 D c f) -> Int -> Gen' sized (M1 D c f p) Source #

GAProduct f => GA Unsized (M1 C c f) Source # 

Methods

ga :: Weights_ (M1 C c f) -> Int -> Gen' Unsized (M1 C c f p) Source #

(GASum (Sized n) f, GASum (Sized n) g, BaseCases n f, BaseCases n g) => GA (Sized n) ((:+:) f g) Source # 

Methods

ga :: Weights_ (f :+: g) -> Int -> Gen' (Sized n) ((f :+: g) p) Source #

(GAProduct f, KnownNat (Arity f)) => GA (Sized n) (M1 C c f) Source # 

Methods

ga :: Weights_ (M1 C c f) -> Int -> Gen' (Sized n) (M1 C c f p) Source #

gArbitrarySingle :: forall sized f p c0. (GA sized f, Weights_ f ~ L c0) => Gen' sized (f p) Source #

gaSum' :: GASum sized f => Weights_ f -> Int -> Gen' sized (f p) Source #

class GASum sized f where Source #

Minimal complete definition

gaSum

Methods

gaSum :: Int -> Weights_ f -> Gen' sized (f p) Source #

Instances

(GASum sized f, GASum sized g) => GASum sized ((:+:) f g) Source # 

Methods

gaSum :: Int -> Weights_ (f :+: g) -> Gen' sized ((f :+: g) p) Source #

GAProduct f => GASum sized (M1 i c f) Source # 

Methods

gaSum :: Int -> Weights_ (M1 i c f) -> Gen' sized (M1 i c f p) Source #

class GAProduct f where Source #

Minimal complete definition

gaProduct

Methods

gaProduct :: Gen (f p) Source #

Instances

GAProduct U1 Source # 

Methods

gaProduct :: Gen (U1 p) Source #

Arbitrary c => GAProduct (K1 i c) Source # 

Methods

gaProduct :: Gen (K1 i c p) Source #

(GAProduct f, GAProduct g) => GAProduct ((:*:) f g) Source # 

Methods

gaProduct :: Gen ((f :*: g) p) Source #

GAProduct f => GAProduct (M1 i c f) Source # 

Methods

gaProduct :: Gen (M1 i c f p) Source #

type family Arity f :: Nat where ... Source #

Equations

Arity (f :*: g) = Arity f + Arity g 
Arity (M1 _i _c _f) = 1 

newtype Tagged a b Source #

Constructors

Tagged 

Fields

Instances

Functor (Tagged a) Source # 

Methods

fmap :: (a -> b) -> Tagged a a -> Tagged a b #

(<$) :: a -> Tagged a b -> Tagged a a #

Use the Z and S data types to define the depths of values used by genericArbitrary' to make generators terminate.

data Z Source #

Zero

Constructors

Z 

Instances

ListBaseCases Z (K1 i c) Source # 

Methods

listBaseCases :: Alternative u => Tagged Z (u (K1 i c p)) Source #

data S n Source #

Successor

Constructors

S n 

Instances

(Generic c, ListBaseCases n (Rep c)) => ListBaseCases (S n) (K1 i c) Source # 

Methods

listBaseCases :: Alternative u => Tagged (S n) (u (K1 i c p)) Source #

newtype Weighted a Source #

Constructors

Weighted (Maybe (Int -> Gen a, Int)) 

Instances

Functor Weighted Source # 

Methods

fmap :: (a -> b) -> Weighted a -> Weighted b #

(<$) :: a -> Weighted b -> Weighted a #

Applicative Weighted Source # 

Methods

pure :: a -> Weighted a #

(<*>) :: Weighted (a -> b) -> Weighted a -> Weighted b #

(*>) :: Weighted a -> Weighted b -> Weighted b #

(<*) :: Weighted a -> Weighted b -> Weighted a #

Alternative Weighted Source # 

Methods

empty :: Weighted a #

(<|>) :: Weighted a -> Weighted a -> Weighted a #

some :: Weighted a -> Weighted [a] #

many :: Weighted a -> Weighted [a] #

class BaseCases n f where Source #

Minimal complete definition

baseCases

Methods

baseCases :: Weights_ f -> Int -> Tagged n (Weighted (f p)) Source #

Instances

(BaseCases n f, BaseCases n g) => BaseCases n ((:+:) f g) Source # 

Methods

baseCases :: Weights_ (f :+: g) -> Int -> Tagged n (Weighted ((f :+: g) p)) Source #

ListBaseCases n f => BaseCases n (M1 i c f) Source # 

Methods

baseCases :: Weights_ (M1 i c f) -> Int -> Tagged n (Weighted (M1 i c f p)) Source #

class ListBaseCases n f where Source #

A ListBaseCases n (Rep a) constraint basically provides the list of values of type a with depth at most n.

Minimal complete definition

listBaseCases

Methods

listBaseCases :: Alternative u => Tagged n (u (f p)) Source #

Instances

ListBaseCases n U1 Source # 

Methods

listBaseCases :: Alternative u => Tagged n (u (U1 p)) Source #

(ListBaseCases n f, ListBaseCases n g) => ListBaseCases n ((:*:) f g) Source # 

Methods

listBaseCases :: Alternative u => Tagged n (u ((f :*: g) p)) Source #

(ListBaseCases n f, ListBaseCases n g) => ListBaseCases n ((:+:) f g) Source # 

Methods

listBaseCases :: Alternative u => Tagged n (u ((f :+: g) p)) Source #

ListBaseCases Z (K1 i c) Source # 

Methods

listBaseCases :: Alternative u => Tagged Z (u (K1 i c p)) Source #

ListBaseCases n f => ListBaseCases n (M1 i c f) Source # 

Methods

listBaseCases :: Alternative u => Tagged n (u (M1 i c f p)) Source #

(Generic c, ListBaseCases n (Rep c)) => ListBaseCases (S n) (K1 i c) Source # 

Methods

listBaseCases :: Alternative u => Tagged (S n) (u (K1 i c p)) Source #

type BaseCases' n a = (Generic a, ListBaseCases n (Rep a)) Source #

For convenience.