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

Constrained.Generation

Description

All the things that are necessary for generation and shrinking.

Synopsis

Documentation

genFromSpecT ∷ ∀ a m. (HasCallStack, HasSpec a, MonadGenError m) ⇒ Specification a → GenT m a Source #

Generate a value that satisfies the spec. This function can fail if the spec is inconsistent, there is a dependency error, or if the underlying generators are not flexible enough.

substituteAndSimplifyTermSubstTerm a → Term a Source #

Apply a substitution and simplify the resulting term if the substitution changed the term.

simplifyTerm ∷ ∀ a. Term a → Term a Source #

Simplify a Term, if the Term is an App, apply the rewrite rules chosen by the (Logic sym t bs a) instance attached to the function witness f

computeSpecSimplified ∷ ∀ a. (HasSpec a, HasCallStack) ⇒ Var a → PredGE (Specification a) Source #

Precondition: the Pred defines the `Var a` Runs in GE in order for us to have detailed context on failure.

computeSpec ∷ ∀ a. (HasSpec a, HasCallStack) ⇒ Var a → PredGE (Specification a) Source #

Precondition: the `Pred fn` defines the `Var a`. Runs in GE in order for us to have detailed context on failure.

caseSpec ∷ ∀ as. HasSpec (SumOver as) ⇒ Maybe StringList (Weighted Specification) as → Specification (SumOver as) Source #

Turn a list of branches into a SumSpec. If all the branches fail return an ErrorSpec. Note the requirement of HasSpec(SumOver).

data SumSpec a b Source #

The Specification for Sums.

Instances

Instances details
(Arbitrary (Specification a), Arbitrary (Specification b)) ⇒ Arbitrary (SumSpec a b) Source # 
Instance details

Defined in Constrained.Test

Methods

arbitraryGen (SumSpec a b) Source #

shrinkSumSpec a b → [SumSpec a b] Source #

(HasSpec a, HasSpec b, KnownNat (CountCases b)) ⇒ Monoid (SumSpec a b) Source # 
Instance details

Defined in Constrained.Generation

Methods

memptySumSpec a b #

mappendSumSpec a b → SumSpec a b → SumSpec a b #

mconcat ∷ [SumSpec a b] → SumSpec a b #

(HasSpec a, HasSpec b) ⇒ Semigroup (SumSpec a b) Source # 
Instance details

Defined in Constrained.Generation

Methods

(<>)SumSpec a b → SumSpec a b → SumSpec a b #

sconcatNonEmpty (SumSpec a b) → SumSpec a b #

stimesIntegral b0 ⇒ b0 → SumSpec a b → SumSpec a b #

(KnownNat (CountCases b), HasSpec a, HasSpec b) ⇒ Show (SumSpec a b) Source # 
Instance details

Defined in Constrained.Generation

Methods

showsPrecIntSumSpec a b → ShowS #

showSumSpec a b → String #

showList ∷ [SumSpec a b] → ShowS #

pattern SumSpecMaybe (Int, Int) → Specification a → Specification b → SumSpec a b Source #

genFromSpec ∷ ∀ a. (HasCallStack, HasSpec a) ⇒ Specification a → Gen a Source #

A version of genFromSpecT that simply errors if the generator fails

genFromSpecWithSeed ∷ ∀ a. (HasCallStack, HasSpec a) ⇒ IntIntSpecification a → a Source #

A version of genFromSpecT that takes a seed and a size and gives you a result

debugSpec ∷ ∀ a. HasSpec a ⇒ Specification a → IO () Source #

A version of genFromSpecT that runs in the IO monad. Good for debugging.

shrinkWithSpec ∷ ∀ a. HasSpec a ⇒ Specification a → a → [a] Source #

shrinkFromPredsHasSpec a ⇒ PredVar a → a → [a] Source #

fixupWithSpec ∷ ∀ a. HasSpec a ⇒ Specification a → a → Maybe a Source #

prepareLinearizationPredGE SolverPlan Source #

Linearize a predicate, turning it into a list of variables to solve and their defining constraints such that each variable can be solved independently.

flattenPredPred → [Pred] Source #

Flatten nested Let, Exists, and And in a `Pred fn`. Let and Exists bound variables become free in the result.

mergeSolverStageSolverStage → [SolverStage] → [SolverStage] Source #

Does nothing if the variable is not in the plan already.

genFromPreds ∷ ∀ m. MonadGenError m ⇒ EnvPredGenT m Env Source #

Generate a satisfying Env for a `p : Pred fn`. The Env contains values for all the free variables in `flattenPred p`.

backPropagationSolverPlanSolverPlan Source #

Push as much information we can backwards through the plan.

data EqW ∷ [Type] → TypeType where Source #

Constructors

EqualW ∷ (Eq a, HasSpec a) ⇒ EqW '[a, a] Bool 

Instances

Instances details
Syntax EqW Source # 
Instance details

Defined in Constrained.Generation

Methods

isInfix ∷ ∀ (dom ∷ [Type]) rng. EqW dom rng → Bool Source #

prettySymbol ∷ ∀ deps (dom ∷ [Type]) rng ann. EqW dom rng → List (TermD deps) dom → IntMaybe (Doc ann) Source #

Logic EqW Source # 
Instance details

Defined in Constrained.Generation

Methods

propagateTypeSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires EqW as b, HasSpec a) ⇒ EqW as b → ListCtx Value as (HOLE a) → TypeSpec b → [b] → Specification a Source #

propagateMemberSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires EqW as b, HasSpec a) ⇒ EqW as b → ListCtx Value as (HOLE a) → NonEmpty b → Specification a Source #

propagate ∷ ∀ (as ∷ [Type]) b a. (AppRequires EqW as b, HasSpec a) ⇒ EqW as b → ListCtx Value as (HOLE a) → Specification b → Specification a Source #

rewriteRules ∷ ∀ (dom ∷ [Type]) rng. (TypeList dom, Typeable dom, HasSpec rng, All HasSpec dom) ⇒ EqW dom rng → List Term dom → Evidence (AppRequires EqW dom rng) → Maybe (Term rng) Source #

mapTypeSpec ∷ (HasSpec a, HasSpec b) ⇒ EqW '[a] b → TypeSpec a → Specification b Source #

saturate ∷ ∀ (dom ∷ [Type]). EqW dom BoolList Term dom → [Pred] Source #

Semantics EqW Source # 
Instance details

Defined in Constrained.Generation

Methods

semantics ∷ ∀ (d ∷ [Type]) r. EqW d r → FunTy d r Source #

Show (EqW d r) Source # 
Instance details

Defined in Constrained.Generation

Methods

showsPrecIntEqW d r → ShowS #

showEqW d r → String #

showList ∷ [EqW d r] → ShowS #

Eq (EqW dom rng) Source # 
Instance details

Defined in Constrained.Generation

Methods

(==)EqW dom rng → EqW dom rng → Bool #

(/=)EqW dom rng → EqW dom rng → Bool #

(==.)HasSpec a ⇒ Term a → Term a → Term Bool infix 4 Source #

pattern Equal ∷ ∀ b. () ⇒ ∀ a. (b ~ Bool, Eq a, HasSpec a) ⇒ Term a → Term a → Term b Source #

whenTrue ∷ ∀ p. IsPred p ⇒ Term Bool → p → Pred Source #

pinnedBy ∷ ∀ a. HasSpec a ⇒ Var a → PredMaybe (Term a) Source #

Is the variable x pinned to some free term in p? (free term meaning that all the variables in the term are free in p).

TODO: complete this with more cases!

guardSumSpec ∷ ∀ a b. (HasSpec a, HasSpec b, KnownNat (CountCases b)) ⇒ [String] → SumSpec a b → Specification (Sum a b) Source #

type family CountCases a where ... Source #

Equations

CountCases (Sum a b) = 1 + CountCases b 
CountCases _ = 1 

data SumW dom rng where Source #

Constructors

InjLeftWSumW '[a] (Sum a b) 
InjRightWSumW '[b] (Sum a b) 

Instances

Instances details
Syntax SumW Source # 
Instance details

Defined in Constrained.Generation

Methods

isInfix ∷ ∀ (dom ∷ [Type]) rng. SumW dom rng → Bool Source #

prettySymbol ∷ ∀ deps (dom ∷ [Type]) rng ann. SumW dom rng → List (TermD deps) dom → IntMaybe (Doc ann) Source #

Logic SumW Source # 
Instance details

Defined in Constrained.Generation

Methods

propagateTypeSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires SumW as b, HasSpec a) ⇒ SumW as b → ListCtx Value as (HOLE a) → TypeSpec b → [b] → Specification a Source #

propagateMemberSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires SumW as b, HasSpec a) ⇒ SumW as b → ListCtx Value as (HOLE a) → NonEmpty b → Specification a Source #

propagate ∷ ∀ (as ∷ [Type]) b a. (AppRequires SumW as b, HasSpec a) ⇒ SumW as b → ListCtx Value as (HOLE a) → Specification b → Specification a Source #

rewriteRules ∷ ∀ (dom ∷ [Type]) rng. (TypeList dom, Typeable dom, HasSpec rng, All HasSpec dom) ⇒ SumW dom rng → List Term dom → Evidence (AppRequires SumW dom rng) → Maybe (Term rng) Source #

mapTypeSpec ∷ (HasSpec a, HasSpec b) ⇒ SumW '[a] b → TypeSpec a → Specification b Source #

saturate ∷ ∀ (dom ∷ [Type]). SumW dom BoolList Term dom → [Pred] Source #

Semantics SumW Source # 
Instance details

Defined in Constrained.Generation

Methods

semantics ∷ ∀ (d ∷ [Type]) r. SumW d r → FunTy d r Source #

Show (SumW dom rng) Source # 
Instance details

Defined in Constrained.Generation

Methods

showsPrecIntSumW dom rng → ShowS #

showSumW dom rng → String #

showList ∷ [SumW dom rng] → ShowS #

Eq (SumW dom rng) Source # 
Instance details

Defined in Constrained.Generation

Methods

(==)SumW dom rng → SumW dom rng → Bool #

(/=)SumW dom rng → SumW dom rng → Bool #

injLeft_ ∷ (HasSpec a, HasSpec b, KnownNat (CountCases b)) ⇒ Term a → Term (Sum a b) Source #

injRight_ ∷ (HasSpec a, HasSpec b, KnownNat (CountCases b)) ⇒ Term b → Term (Sum a b) Source #

pattern InjRight ∷ ∀ c. () ⇒ ∀ a b. (c ~ Sum a b, AppRequires SumW '[b] c) ⇒ Term b → Term c Source #

pattern InjLeft ∷ ∀ c. () ⇒ ∀ a b. (c ~ Sum a b, AppRequires SumW '[a] c) ⇒ Term a → Term c Source #

data BoolW (dom ∷ [Type]) (rng ∷ Type) where Source #

Operations on Bool

Constructors

NotWBoolW '[Bool] Bool 
OrWBoolW '[Bool, Bool] Bool 

Instances

Instances details
Syntax BoolW Source # 
Instance details

Defined in Constrained.Generation

Methods

isInfix ∷ ∀ (dom ∷ [Type]) rng. BoolW dom rng → Bool Source #

prettySymbol ∷ ∀ deps (dom ∷ [Type]) rng ann. BoolW dom rng → List (TermD deps) dom → IntMaybe (Doc ann) Source #

Logic BoolW Source # 
Instance details

Defined in Constrained.Generation

Methods

propagateTypeSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires BoolW as b, HasSpec a) ⇒ BoolW as b → ListCtx Value as (HOLE a) → TypeSpec b → [b] → Specification a Source #

propagateMemberSpec ∷ ∀ (as ∷ [Type]) b a. (AppRequires BoolW as b, HasSpec a) ⇒ BoolW as b → ListCtx Value as (HOLE a) → NonEmpty b → Specification a Source #

propagate ∷ ∀ (as ∷ [Type]) b a. (AppRequires BoolW as b, HasSpec a) ⇒ BoolW as b → ListCtx Value as (HOLE a) → Specification b → Specification a Source #

rewriteRules ∷ ∀ (dom ∷ [Type]) rng. (TypeList dom, Typeable dom, HasSpec rng, All HasSpec dom) ⇒ BoolW dom rng → List Term dom → Evidence (AppRequires BoolW dom rng) → Maybe (Term rng) Source #

mapTypeSpec ∷ (HasSpec a, HasSpec b) ⇒ BoolW '[a] b → TypeSpec a → Specification b Source #

saturate ∷ ∀ (dom ∷ [Type]). BoolW dom BoolList Term dom → [Pred] Source #

Semantics BoolW Source # 
Instance details

Defined in Constrained.Generation

Methods

semantics ∷ ∀ (d ∷ [Type]) r. BoolW d r → FunTy d r Source #

Show (BoolW dom rng) Source # 
Instance details

Defined in Constrained.Generation

Methods

showsPrecIntBoolW dom rng → ShowS #

showBoolW dom rng → String #

showList ∷ [BoolW dom rng] → ShowS #

Eq (BoolW dom rng) Source # 
Instance details

Defined in Constrained.Generation

Methods

(==)BoolW dom rng → BoolW dom rng → Bool #

(/=)BoolW dom rng → BoolW dom rng → Bool #

boolSemBoolW dom rng → FunTy dom rng Source #

okOrBoolBoolSpecification Bool Source #

We have something like (constant ||. HOLE) must evaluate to need. Return a (Specification Bool) for HOLE, that makes that True.

data SolverStage where Source #

Constructors

SolverStage 

Fields

Instances

Instances details
Pretty SolverStage Source # 
Instance details

Defined in Constrained.Generation

Methods

prettySolverStageDoc ann Source #

prettyList ∷ [SolverStage] → Doc ann Source #

data SolverPlan Source #

Instances

Instances details
Pretty SolverPlan Source # 
Instance details

Defined in Constrained.Generation

Methods

prettySolverPlanDoc ann Source #

prettyList ∷ [SolverPlan] → Doc ann Source #

Orphan instances

(HasSpec a, HasSpec b, KnownNat (CountCases b)) ⇒ HasSpec (Sum a b) Source #

The HasSpec Sum instance

Instance details

Associated Types

type TypeSpec (Sum a b) Source #

type Prerequisites (Sum a b) Source #