Module

Control.Monad.Gen

#choose

choose :: forall m a. MonadGen m => m a -> m a -> m a

Creates a generator that outputs a value chosen from one of two existing existing generators with even probability.

#oneOf

oneOf :: forall m f a. MonadGen m => Foldable1 f => f (m a) -> m a

Creates a generator that outputs a value chosen from a selection of existing generators with uniform probability.

#frequency

frequency :: forall m f a. MonadGen m => Foldable1 f => f (Tuple Number (m a)) -> m a

Creates a generator that outputs a value chosen from a selection of existing generators, where the selection has weight values for the probability of choice for each generator. The probability values will be normalised.

#elements

elements :: forall m f a. MonadGen m => Foldable1 f => f a -> m a

Creates a generator that outputs a value chosen from a selection with uniform probability.

#unfoldable

unfoldable :: forall m f a. MonadRec m => MonadGen m => Unfoldable f => m a -> m (f a)

Creates a generator that produces unfoldable structures based on an existing generator for the elements.

The size of the unfoldable will be determined by the current size state for the generator. To generate an unfoldable structure of a particular size, use the resize function from the MonadGen class first.

#suchThat

suchThat :: forall m a. MonadRec m => MonadGen m => m a -> (a -> Boolean) -> m a

Creates a generator that repeatedly run another generator until its output matches a given predicate. This will never halt if the predicate always fails.

#filtered

filtered :: forall m a. MonadRec m => MonadGen m => m (Maybe a) -> m a

Creates a generator that repeatedly run another generator until it produces Just node. This will never halt if the input generator always produces Nothing.

Re-exports from Control.Monad.Gen.Class

#Size

type Size = Int

#MonadGen

class (Monad m) <= MonadGen m  where

A class for random generator implementations.

Instances should provide implementations for the generation functions that return choices with uniform probability.

Members

  • chooseInt :: Int -> Int -> m Int

    Chooses an integer in the specified (inclusive) range.

  • chooseFloat :: Number -> Number -> m Number

    Chooses an floating point number in the specified (inclusive) range.

  • chooseBool :: m Boolean

    Chooses a random boolean value.

  • resize :: forall a. (Size -> Size) -> m a -> m a

    Modifies the size state for a random generator.

  • sized :: forall a. (Size -> m a) -> m a

    Runs a generator, passing in the current size state.

Modules