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

Constrained.NumOrd

Synopsis

Documentation

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

Constructors

LessOrEqualWOrdLike a ⇒ OrdW '[a, a] Bool 
LessWOrdLike a ⇒ OrdW '[a, a] Bool 
GreaterOrEqualWOrdLike a ⇒ OrdW '[a, a] Bool 
GreaterWOrdLike a ⇒ OrdW '[a, a] Bool 

Instances

Instances details
Syntax OrdW Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

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

Logic OrdW Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

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

propagate ∷ ∀ (as ∷ [Type]) b a. (AppRequires OrdW as b, HasSpec a) ⇒ OrdW 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) ⇒ OrdW dom rng → List Term dom → Evidence (AppRequires OrdW dom rng) → Maybe (Term rng) Source #

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

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

Semantics OrdW Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

Show (OrdW ds r) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

showsPrecIntOrdW ds r → ShowS #

showOrdW ds r → String #

showList ∷ [OrdW ds r] → ShowS #

Eq (OrdW ds r) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

(==)OrdW ds r → OrdW ds r → Bool #

(/=)OrdW ds r → OrdW ds r → Bool #

class (Ord a, HasSpec a) ⇒ OrdLike a where Source #

Minimal complete definition

Nothing

Methods

leqSpec ∷ a → Specification a Source #

default leqSpec ∷ (GenericRequires a, OrdLike (SimpleRep a)) ⇒ a → Specification a Source #

ltSpec ∷ a → Specification a Source #

default ltSpec ∷ (OrdLike (SimpleRep a), GenericRequires a) ⇒ a → Specification a Source #

geqSpec ∷ a → Specification a Source #

default geqSpec ∷ (OrdLike (SimpleRep a), GenericRequires a) ⇒ a → Specification a Source #

gtSpec ∷ a → Specification a Source #

default gtSpec ∷ (OrdLike (SimpleRep a), GenericRequires a) ⇒ a → Specification a Source #

Instances

Instances details
(Ord a, HasSpec a, MaybeBounded a, Num a, TypeSpec a ~ NumSpec a) ⇒ OrdLike a Source #

This instance should be general enough for every type of Number that has a NumSpec as its TypeSpec

Instance details

Defined in Constrained.NumOrd

class MaybeBounded a where Source #

Minimal complete definition

Nothing

Methods

lowerBoundMaybe a Source #

default lowerBoundBounded a ⇒ Maybe a Source #

upperBoundMaybe a Source #

default upperBoundBounded a ⇒ Maybe a Source #

Instances

Instances details
MaybeBounded Int16 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Int32 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Int64 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Int8 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Word16 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Word32 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Word64 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Word8 Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Integer Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Natural Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Float Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded Int Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded (Ratio Integer) Source # 
Instance details

Defined in Constrained.NumOrd

MaybeBounded (Unbounded a) Source # 
Instance details

Defined in Constrained.NumOrd

newtype Unbounded a Source #

Constructors

Unbounded a 

Instances

Instances details
MaybeBounded (Unbounded a) Source # 
Instance details

Defined in Constrained.NumOrd

data NumSpec n Source #

Constructors

NumSpecInterval (Maybe n) (Maybe n) 

Instances

Instances details
(Arbitrary a, Ord a) ⇒ Arbitrary (NumSpec a) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

arbitraryGen (NumSpec a) Source #

shrinkNumSpec a → [NumSpec a] Source #

Ord n ⇒ Monoid (NumSpec n) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

memptyNumSpec n #

mappendNumSpec n → NumSpec n → NumSpec n #

mconcat ∷ [NumSpec n] → NumSpec n #

Ord n ⇒ Semigroup (NumSpec n) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

(<>)NumSpec n → NumSpec n → NumSpec n #

sconcatNonEmpty (NumSpec n) → NumSpec n #

stimesIntegral b ⇒ b → NumSpec n → NumSpec n #

Num (NumSpec Integer) Source # 
Instance details

Defined in Constrained.NumOrd

Show n ⇒ Show (NumSpec n) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

showsPrecIntNumSpec n → ShowS #

showNumSpec n → String #

showList ∷ [NumSpec n] → ShowS #

Ord n ⇒ Eq (NumSpec n) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

(==)NumSpec n → NumSpec n → Bool #

(/=)NumSpec n → NumSpec n → Bool #

shrinkWithNumSpecArbitrary n ⇒ NumSpec n → n → [n] Source #

constrainInterval ∷ (MonadGenError m, Ord a, Num a, Show a) ⇒ Maybe a → Maybe a → Integer → m (a, a) Source #

conformsToNumSpecOrd n ⇒ n → NumSpec n → Bool Source #

nubOrdOrd a ⇒ [a] → [a] Source #

Strip out duplicates (in n-log(n) time, by building an intermediate Set)

nubOrdMemberSpecOrd a ⇒ String → [a] → Specification a Source #

Builds a MemberSpec, but returns an Error spec if the list is empty

lowBoundBounded n ⇒ Maybe n → n Source #

highBoundBounded n ⇒ Maybe n → n Source #

countSpec ∷ ∀ n. (Bounded n, Integral n) ⇒ NumSpec n → Integer Source #

The exact count of the number elements in a Bounded NumSpec

finiteSize ∷ ∀ n. (Integral n, Bounded n) ⇒ Integer Source #

The exact number of elements in a Bounded Integral type.

notInNumSpec ∷ ∀ n. (HasSpec n, TypeSpec n ~ NumSpec n, Bounded n, Integral n) ⇒ NumSpec n → [n] → Specification n Source #

This is an optimizing version of TypeSpec :: TypeSpec n -> [n] -> Specification n for Bounded NumSpecs. notInNumSpec :: Bounded n => TypeSpec n -> [n] -> Specification n We use this function to specialize the (HasSpec t) method typeSpecOpt for Bounded n. So given (TypeSpec interval badlist) we might want to transform it to (MemberSpec goodlist) There are 2 opportunities where this can payoff big time. 1) Suppose the total count of the elements in the interval is < length badlist we can then return (MemberSpec (filter elements (notElem badlist))) this must be smaller than (TypeSpec interval badlist) because the filtered list must be smaller than badlist 2) Suppose the type t is finite with size N. If the length of the badlist > (N/2), then the number of possible good things must be smaller than (length badlist), because (possible good + bad == N), so regardless of the count of the interval (MemberSpec (filter elements (notElem badlist))) is better. Sometimes much better. Example, let n be the finite set {0,1,2,3,4,5,6,7,8,9} and the bad list be [0,1,3,4,5,6,8,9] (TypeSpec [0..9] [0,1,3,4,5,6,8,9]) = filter {0,1,2,3,4,5,6,7,8,9} (notElem [0,1,3,4,5,6,8,9]) = [2,7] So (MemberSpec [2,7]) is better than (TypeSpec [0..9] [0,1,3,4,5,6,8,9]). This works no matter what the count of interval is. We only need the (length badlist > (N/2)).

guardEmpty ∷ (Ord n, Num n) ⇒ Maybe n → Maybe n → NumSpec n → NumSpec n Source #

addNumSpec ∷ (Ord n, Num n) ⇒ NumSpec n → NumSpec n → NumSpec n Source #

subNumSpec ∷ (Ord n, Num n) ⇒ NumSpec n → NumSpec n → NumSpec n Source #

multNumSpec ∷ (Ord n, Num n) ⇒ NumSpec n → NumSpec n → NumSpec n Source #

negNumSpecNum n ⇒ NumSpec n → NumSpec n Source #

data T x Source #

T is a sort of special version of Maybe, with two Nothings. Given:: NumSpecInterval (Maybe n) (Maybe n) -> Numspec We can't distinguish between the two Nothings in (NumSpecInterval Nothing Nothing) But using (NumSpecInterval NegInf PosInf) we can, In fact we can make a total ordering on T So an ascending Sorted [T x] would all the NegInf on the left and all the PosInf on the right, with the Ok's sorted in between. I.e. [NegInf, NegInf, Ok 3, Ok 6, Ok 12, Pos Inf]

Constructors

NegInf 
Ok x 
PosInf 

Instances

Instances details
Show x ⇒ Show (T x) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

showsPrecIntT x → ShowS #

showT x → String #

showList ∷ [T x] → ShowS #

Eq x ⇒ Eq (T x) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

(==)T x → T x → Bool #

(/=)T x → T x → Bool #

Ord x ⇒ Ord (T x) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

compareT x → T x → Ordering #

(<)T x → T x → Bool #

(<=)T x → T x → Bool #

(>)T x → T x → Bool #

(>=)T x → T x → Bool #

maxT x → T x → T x #

minT x → T x → T x #

unTT x → Maybe x Source #

negMaybe x → T x Source #

Use this on the lower bound. I.e. lo from pair (lo,hi)

posMaybe x → T x Source #

Use this on the upper bound. I.e. hi from pair (lo,hi)

multTNum x ⇒ T x → T x → T x Source #

multiply two (T x), correctly handling the infinities NegInf and PosInf

type Number n = (Num n, Enum n, TypeSpec n ~ NumSpec n, Num (NumSpec n), HasSpec n, Ord n) Source #

What constraints we need to make HasSpec instance for a Haskell numeric type. By abstracting over this, we can avoid making actual HasSpec instances until all the requirements (HasSpec Bool, HasSpec(Sum a b)) have been met in Constrained.TheKnot.

operateSpecNumber n ⇒ String → (n → n → n) → (TypeSpec n → TypeSpec n → TypeSpec n) → Specification n → Specification n → Specification n Source #

let n be some numeric type, and f and ft be operations on n and (TypeSpec n) Then lift these operations from (TypeSpec n) to (Specification n) Normally f will be a (Num n) instance method (+,-,*) on n, and ft will be a a (Num (TypeSpec n)) instance method (+,-,*) on (TypeSpec n) But this will work for any operations f and ft with the right types

cardinality ∷ ∀ a. (Number Integer, HasSpec a) ⇒ Specification a → Specification Integer Source #

Put some (admittedly loose bounds) on the number of solutions that genFromTypeSpec might return. For lots of types, there is no way to be very accurate. Here we lift the HasSpec methods cardinalTrueSpec and cardinalTypeSpec from (TypeSpec Integer) to (Specification Integer)

cardinalNumSpec ∷ ∀ n. (Integral n, MaybeBounded n, HasSpec n) ⇒ NumSpec n → Specification Integer Source #

A generic function to use as an instance for the HasSpec method cardinalTypeSpec :: HasSpec a => TypeSpec a -> Specification Integer for types n such that (TypeSpec n ~ NumSpec n)

class (Num a, HasSpec a) ⇒ NumLike a where Source #

Minimal complete definition

Nothing

Methods

subtractSpec ∷ a → TypeSpec a → Specification a Source #

negateSpecTypeSpec a → Specification a Source #

safeSubtract ∷ a → a → Maybe a Source #

default safeSubtract ∷ (HasSimpleRep a, NumLike (SimpleRep a)) ⇒ a → a → Maybe a Source #

Instances

Instances details
Numeric a ⇒ NumLike a Source # 
Instance details

Defined in Constrained.NumOrd

data IntW (as ∷ [Type]) b where Source #

Constructors

AddWNumLike a ⇒ IntW '[a, a] a 
NegateWNumLike a ⇒ IntW '[a] a 

Instances

Instances details
Syntax IntW Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

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

Logic IntW Source #

Just a note that these instances won't work until we are in a context where there is a HasSpec instance of a, which (NumLike a) demands. This happens in Constrained.Experiment.TheKnot

Instance details

Defined in Constrained.NumOrd

Methods

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

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

propagate ∷ ∀ (as ∷ [Type]) b a. (AppRequires IntW as b, HasSpec a) ⇒ IntW 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) ⇒ IntW dom rng → List Term dom → Evidence (AppRequires IntW dom rng) → Maybe (Term rng) Source #

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

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

Semantics IntW Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

Show (IntW d r) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

showsPrecIntIntW d r → ShowS #

showIntW d r → String #

showList ∷ [IntW d r] → ShowS #

Eq (IntW dom rng) Source # 
Instance details

Defined in Constrained.NumOrd

Methods

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

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

addFn ∷ ∀ a. NumLike a ⇒ Term a → Term a → Term a Source #

negateFn ∷ ∀ a. NumLike a ⇒ Term a → Term a Source #

(+.)NumLike a ⇒ Term a → Term a → Term a infix 4 Source #

negate_NumLike a ⇒ Term a → Term a Source #

(-.)Numeric n ⇒ Term n → Term n → Term n infix 4 Source #

(<=.) ∷ ∀ a. OrdLike a ⇒ Term a → Term a → Term Bool infixr 4 Source #

(<.) ∷ ∀ a. OrdLike a ⇒ Term a → Term a → Term Bool infixr 4 Source #

(>=.) ∷ ∀ a. OrdLike a ⇒ Term a → Term a → Term Bool infixr 4 Source #

(>.) ∷ ∀ a. OrdLike a ⇒ Term a → Term a → Term Bool infixr 4 Source #

Orphan instances

Arbitrary Natural Source # 
Instance details

HasSpec Int16 Source # 
Instance details

Associated Types

type TypeSpec Int16 Source #

type Prerequisites Int16 Source #

HasSpec Int32 Source # 
Instance details

Associated Types

type TypeSpec Int32 Source #

type Prerequisites Int32 Source #

HasSpec Int64 Source # 
Instance details

Associated Types

type TypeSpec Int64 Source #

type Prerequisites Int64 Source #

HasSpec Int8 Source # 
Instance details

Associated Types

type TypeSpec Int8 Source #

type Prerequisites Int8 Source #

HasSpec Word16 Source # 
Instance details

Associated Types

type TypeSpec Word16 Source #

type Prerequisites Word16 Source #

HasSpec Word32 Source # 
Instance details

Associated Types

type TypeSpec Word32 Source #

type Prerequisites Word32 Source #

HasSpec Word64 Source # 
Instance details

Associated Types

type TypeSpec Word64 Source #

type Prerequisites Word64 Source #

HasSpec Word8 Source # 
Instance details

Associated Types

type TypeSpec Word8 Source #

type Prerequisites Word8 Source #

HasSpec Integer Source # 
Instance details

HasSpec Natural Source # 
Instance details

HasSpec Float Source # 
Instance details

Associated Types

type TypeSpec Float Source #

type Prerequisites Float Source #

HasSpec Int Source # 
Instance details

Associated Types

type TypeSpec Int Source #

type Prerequisites Int Source #

Random Natural Source # 
Instance details

Methods

randomRRandomGen g ⇒ (Natural, Natural) → g → (Natural, g) Source #

randomRandomGen g ⇒ g → (Natural, g) Source #

randomRsRandomGen g ⇒ (Natural, Natural) → g → [Natural] Source #

randomsRandomGen g ⇒ g → [Natural] Source #

Uniform Natural Source # 
Instance details

Methods

uniformMStatefulGen g m ⇒ g → m Natural Source #

Number IntegerNum (Specification Integer) Source #

This is very liberal, since in lots of cases it returns TrueSpec. for example all operations on SuspendedSpec, and certain operations between TypeSpec and MemberSpec. Perhaps we should remove it. Only the addSpec (+) and multSpec (*) methods are used. But, it is kind of cool ... In Fact we can use this to make Num(Specification n) instance for any n. But, only Integer is safe, because in all other types (+) and especially (-) can lead to overflow or underflow failures.

Instance details

NumLike a ⇒ Num (Term a) Source # 
Instance details

Methods

(+)Term a → Term a → Term a #

(-)Term a → Term a → Term a #

(*)Term a → Term a → Term a #

negateTerm a → Term a #

absTerm a → Term a #

signumTerm a → Term a #

fromIntegerIntegerTerm a #

HasSpec (Ratio Integer) Source # 
Instance details

Random (Ratio Integer) Source # 
Instance details

Methods

randomRRandomGen g ⇒ (Ratio Integer, Ratio Integer) → g → (Ratio Integer, g) Source #

randomRandomGen g ⇒ g → (Ratio Integer, g) Source #

randomRsRandomGen g ⇒ (Ratio Integer, Ratio Integer) → g → [Ratio Integer] Source #

randomsRandomGen g ⇒ g → [Ratio Integer] Source #