constrained-generators-0.2.0.0: Framework for generating constrained random data using a subset of first order logic
Safe HaskellSafe-Inferred
LanguageHaskell2010

Constrained.GenT

Synopsis

Documentation

class Monad m ⇒ MonadGenError m where Source #

A class for different types of errors with a stack of explain calls to narrow down problems. The (NE.NonEmpty String) means one cannot cause an Error without at least 1 string to explain it.

Methods

genError ∷ HasCallStack ⇒ NonEmpty String → m a Source #

fatalError ∷ HasCallStack ⇒ NonEmpty String → m a Source #

explain ∷ HasCallStack ⇒ NonEmpty String → m a → m a Source #

Instances

Instances details
MonadGenError GE Source # 
Instance details

Defined in Constrained.GenT

Methods

genError ∷ HasCallStack ⇒ NonEmpty String → GE a Source #

fatalError ∷ HasCallStack ⇒ NonEmpty String → GE a Source #

explain ∷ HasCallStack ⇒ NonEmpty String → GE a → GE a Source #

MonadGenError m ⇒ MonadGenError (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

genError ∷ HasCallStack ⇒ NonEmpty String → GenT m a Source #

fatalError ∷ HasCallStack ⇒ NonEmpty String → GenT m a Source #

explain ∷ HasCallStack ⇒ NonEmpty String → GenT m a → GenT m a Source #

genError1MonadGenError m ⇒ String → m a Source #

genError with one line of explanation

fatalError1MonadGenError m ⇒ String → m a Source #

fatalError with one line of explanation

explain1MonadGenError m ⇒ String → m a → m a Source #

explain with one line of explanation

data GE a Source #

The Gen Error monad, distinguishes between fatal errors and non-fatal errors.

Constructors

FatalError [NonEmpty String] (NonEmpty String) 
GenError [NonEmpty String] (NonEmpty String) 
Result [NonEmpty String] a 

Instances

Instances details
Applicative GE Source # 
Instance details

Defined in Constrained.GenT

Methods

pure ∷ a → GE a

(<*>)GE (a → b) → GE a → GE b

liftA2 ∷ (a → b → c) → GE a → GE b → GE c

(*>)GE a → GE b → GE b

(<*)GE a → GE b → GE a

Functor GE Source # 
Instance details

Defined in Constrained.GenT

Methods

fmap ∷ (a → b) → GE a → GE b

(<$) ∷ a → GE b → GE a

Monad GE Source # 
Instance details

Defined in Constrained.GenT

Methods

(>>=)GE a → (a → GE b) → GE b

(>>)GE a → GE b → GE b

return ∷ a → GE a

MonadGenError GE Source # 
Instance details

Defined in Constrained.GenT

Methods

genError ∷ HasCallStack ⇒ NonEmpty String → GE a Source #

fatalError ∷ HasCallStack ⇒ NonEmpty String → GE a Source #

explain ∷ HasCallStack ⇒ NonEmpty String → GE a → GE a Source #

Show a ⇒ Show (GE a) Source # 
Instance details

Defined in Constrained.GenT

Methods

showsPrec ∷ Int → GE a → ShowS

showGE a → String

showList ∷ [GE a] → ShowS

Eq a ⇒ Eq (GE a) Source # 
Instance details

Defined in Constrained.GenT

Methods

(==)GE a → GE a → Bool

(/=)GE a → GE a → Bool

Ord a ⇒ Ord (GE a) Source # 
Instance details

Defined in Constrained.GenT

Methods

compareGE a → GE a → Ordering

(<)GE a → GE a → Bool

(<=)GE a → GE a → Bool

(>)GE a → GE a → Bool

(>=)GE a → GE a → Bool

maxGE a → GE a → GE a

minGE a → GE a → GE a

catGEsMonadGenError m ⇒ [GE a] → m [a] Source #

fromGE ∷ (NonEmpty String → a) → GE a → a Source #

errorGEGE a → a Source #

isOkGE a → Bool Source #

runGEMonadGenError m ⇒ GE r → m r Source #

headGE ∷ Foldable t ⇒ t a → GE a Source #

listFromGEGE [a] → [a] Source #

Turn a `GE [a]` to `[a]`, genError goes to `[]` and fatalError to error.

data GenMode Source #

Generation mode - how strict are we about requiring the generator to succeed. This is necessary because sometimes failing to find a value means there is an actual problem (a generator _should_ be satisfiable but for whatever buggy reason it isn't) and sometimes failing to find a value just means there are no values. The latter case is very relevant when you're generating e.g. lists or sets of values that can be empty.

Constructors

Loose 
Strict 

Instances

Instances details
Show GenMode Source # 
Instance details

Defined in Constrained.GenT

Methods

showsPrec ∷ Int → GenMode → ShowS

showGenMode → String

showList ∷ [GenMode] → ShowS

Eq GenMode Source # 
Instance details

Defined in Constrained.GenT

Methods

(==)GenModeGenMode → Bool

(/=)GenModeGenMode → Bool

Ord GenMode Source # 
Instance details

Defined in Constrained.GenT

Methods

compareGenModeGenMode → Ordering

(<)GenModeGenMode → Bool

(<=)GenModeGenMode → Bool

(>)GenModeGenMode → Bool

(>=)GenModeGenMode → Bool

maxGenModeGenModeGenMode

minGenModeGenModeGenMode

newtype GenT m a Source #

Constructors

GenT 

Fields

Instances

Instances details
MonadGenError m ⇒ MonadFail (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

fail ∷ String → GenT m a

Monad m ⇒ Applicative (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

pure ∷ a → GenT m a

(<*>)GenT m (a → b) → GenT m a → GenT m b

liftA2 ∷ (a → b → c) → GenT m a → GenT m b → GenT m c

(*>)GenT m a → GenT m b → GenT m b

(<*)GenT m a → GenT m b → GenT m a

Functor m ⇒ Functor (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

fmap ∷ (a → b) → GenT m a → GenT m b

(<$) ∷ a → GenT m b → GenT m a

Monad m ⇒ Monad (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

(>>=)GenT m a → (a → GenT m b) → GenT m b

(>>)GenT m a → GenT m b → GenT m b

return ∷ a → GenT m a

MonadGenError m ⇒ MonadGenError (GenT m) Source # 
Instance details

Defined in Constrained.GenT

Methods

genError ∷ HasCallStack ⇒ NonEmpty String → GenT m a Source #

fatalError ∷ HasCallStack ⇒ NonEmpty String → GenT m a Source #

explain ∷ HasCallStack ⇒ NonEmpty String → GenT m a → GenT m a Source #

strictGenGenT m a → Gen (m a) Source #

resizeT ∷ (Int → Int) → GenT m a → GenT m a Source #

pureGen ∷ Applicative m ⇒ Gen a → GenT m a Source #

listOfTMonadGenError m ⇒ GenT GE a → GenT m [a] Source #

listOfUntilLenTMonadGenError m ⇒ GenT GE a → Int → (Int → Bool) → GenT m [a] Source #

Generate a list of elements of length at most goalLen, but accepting failure to get that many elements so long as validLen is true. TODO: possibly one could return "more, fewer, ok" in the validLen instead of Bool

vectorOfTMonadGenError m ⇒ Int → GenT GE a → GenT m [a] Source #

suchThatTMonadGenError m ⇒ GenT m a → (a → Bool) → GenT m a infixl 2 Source #

suchThatWithTryTMonadGenError m ⇒ Int → GenT m a → (a → Bool) → GenT m a Source #

scaleT ∷ (Int → Int) → GenT m a → GenT m a Source #

getMode ∷ Applicative m ⇒ GenT m GenMode Source #

withModeGenModeGenT m a → GenT m a Source #

oneofTMonadGenError m ⇒ [GenT GE a] → GenT m a Source #

frequencyTMonadGenError m ⇒ [(Int, GenT GE a)] → GenT m a Source #

chooseT ∷ (Random a, Ord a, Show a, MonadGenError m) ⇒ (a, a) → GenT m a Source #

sizeT ∷ Monad m ⇒ GenT m Int Source #

inspect ∷ ∀ m x. MonadGenError m ⇒ GenT GE x → GenT m (GE x) Source #

Always succeeds, but returns the internal GE structure for analysis

tryGenTMonadGenError m ⇒ GenT GE a → GenT m (Maybe a) Source #

Ignore all kinds of Errors, by squashing them into Nothing

catchGenTMonadGenError m ⇒ GenT GE a → GenT m (Either (NonEmpty String) a) Source #

catchGenGenT GE a → Gen (Either (NonEmpty String) a) Source #

firstGenT ∷ ∀ m a. MonadGenError m ⇒ [GenT GE a] → GenT m (Either [NonEmpty String] a) Source #

Return the first successfull result from a list of computations, if they all fail return a list of the error messages from each one.

liftGen ∷ ∀ x. (∀ m. MonadGenError m ⇒ GenT m x) → GenT GE x Source #

dropGenMonadGenError m ⇒ GenT GE a → GenT m a Source #

frequency2 ∷ ∀ m a. MonadGenError m ⇒ (Int, GenT GE a) → (Int, GenT GE a) → GenT m a Source #

Run one of the actions with frequency proportional to the count. If it fails, run the other.

push ∷ ∀ m a. MonadGenError m ⇒ [String] → GenT GE a → GenT m a Source #

Temporarily extend the stack while executing m, and revert to the old stack if successful

pushGE ∷ ∀ a. [String] → GE a → GE a Source #