Modulegenvalidity-sydtest-1.0.0.0Haskell2010
Test.Syd.Validity
To use the Spec functions in this module, you will need TypeApplications.
The most interesting functions in this module for most uses are:
- 2 types
- 9 classes
- 215 values
- Packagegenvalidity-sydtest-1.0.0.0
- Exports226
- LanguageHaskell2010
- LicenceMIT
- SourceValidity.hs
Writing properties
0 declarationsCheap generation with shrinking
Cheap assertions
Tests for GenValidity instances
10 declarationsA Spec that specifies that genValid only generates valid data.
In general it is a good idea to add this spec to your test suite if you
write a custom implementation of genValid.
Example usage:
genValidSpec @IntgenValid only generates valid data
genValidGeneratesValid @()genValidGeneratesValid @BoolgenValidGeneratesValid @OrderinggenValidGeneratesValid @ChargenValidGeneratesValid @IntgenValidGeneratesValid @FloatgenValidGeneratesValid @DoublegenValidGeneratesValid @IntegergenValidGeneratesValid @(Maybe Int)genValidGeneratesValid @[Int]The given generator generates only valid data points
shrinkPreservesValidOnGenValid ((:[]) :: Int -> [Int])shrinkValidPreservesValid (pure 5 :: Gen Rational)shrinkingStaysValid (pure 5 :: Gen Double) (\d -> [d - 1, d - 2])shrinkingPreserves (pure 5 :: Gen Int) (:[]) (== 5)Tests for Arbitrary instances involving Validity
2 declarationsA Spec that specifies that arbitrary only generates data that
satisfy isValid
Example usage:
arbitrarySpec @Intarbitrary only generates valid data
arbitraryGeneratesOnlyValid @IntStandard tests involving functions
0 declarationsStandard tests involving validity
The function produces valid output when the input is generated as specified by the given generator.
The function produces valid output when the input is generated by
genValid
The function produces valid output when the input is generated by
arbitrary
Standard tests involving functions that can fail
A class of types that are the result of functions that can fail
Methods
hasFailed :: f a -> BoolresultIfSucceeded :: f a -> Maybe a
The function succeeds if the input is generated by the given generator
The function succeeds if the input is generated by genValid
The function succeeds if the input is generated by arbitrary
The function fails if the input is generated by the given generator
The function produces output that satisfies isValid if it is given input
that is generated by the given generator.
The function produces output that satisfies isValid if it is given input
that is generated by arbitrary.
The function produces output that satisfies isValid if it is given input
that is generated by genValid.
Standard tests involving equivalence of functions
Simple functions
One argument
equivalentOnArbitrary ((* 2) . (+ 1)) ((+ 2) . (* 2) :: Int -> Int)Two arguments
equivalentOnArbitrary2 (+) ((+) :: Int -> Int -> Int)Three arguments
First function can fail
One argument
Two arguments
Second function can fail
One argument
Two arguments
Both functions can fail
One argument
Two arguments
Standard tests involving inverse functions
id is its own inverse function for every type: prop> inverseFunctionsOnArbitrary id (id :: Int -> Int)
Properties involving idempotence
Properties of relations
0 declarationsReflexivity
Reflexive(\prec)
\quad\equiv\quad
\forall a: (a \prec a)
reflexivity ((<=) :: Int -> Int -> Bool)reflexivity ((==) :: Int -> Int -> Bool)reflexivity ((>=) :: Int -> Int -> Bool)reflexivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)reflexivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)reflexivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)reflexivityOnArbitrary ((<=) :: Int -> Int -> Bool)reflexivityOnArbitrary ((==) :: Int -> Int -> Bool)reflexivityOnArbitrary ((>=) :: Int -> Int -> Bool)reflexivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)reflexivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)reflexivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)Transitivity
Transitive(\prec)
\quad\equiv\quad
\forall a, b, c: ((a \prec b) \wedge (b \prec c)) \Rightarrow (a \prec c)
transitivity ((>) :: Int -> Int -> Bool)transitivity ((>=) :: Int -> Int -> Bool)transitivity ((==) :: Int -> Int -> Bool)transitivity ((<=) :: Int -> Int -> Bool)transitivity ((<) :: Int -> Int -> Bool)transitivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)transitivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)transitivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)transitivityOnArbitrary ((>) :: Int -> Int -> Bool)transitivityOnArbitrary ((>=) :: Int -> Int -> Bool)transitivityOnArbitrary ((==) :: Int -> Int -> Bool)transitivityOnArbitrary ((<=) :: Int -> Int -> Bool)transitivityOnArbitrary ((<) :: Int -> Int -> Bool)transitivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)transitivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)transitivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)Antisymmetry
Antisymmetric(\prec, \doteq)
\quad\equiv\quad
\forall a, b: ((a \prec b) \wedge (b \prec a)) \Rightarrow (a \doteq b)
antisymmetry ((>) :: Int -> Int -> Bool)antisymmetry ((>=) :: Int -> Int -> Bool)antisymmetry ((<=) :: Int -> Int -> Bool)antisymmetry ((<) :: Int -> Int -> Bool)antisymmetry (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)antisymmetry (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)antisymmetry (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)antisymmetry ((\x y -> even x && odd y) :: Int -> Int -> Bool)antisymmetryOnArbitrary ((>) :: Int -> Int -> Bool)antisymmetryOnArbitrary ((>=) :: Int -> Int -> Bool)antisymmetryOnArbitrary ((<=) :: Int -> Int -> Bool)antisymmetryOnArbitrary ((<) :: Int -> Int -> Bool)antisymmetryOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)antisymmetryOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)antisymmetryOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)antisymmetryOnArbitrary ((\x y -> even x && odd y) :: Int -> Int -> Bool)Antireflexivity
Antireflexive(\prec)
\quad\equiv\quad
\forall a: \neg (a \prec a)
antireflexivity ((<) :: Int -> Int -> Bool)antireflexivity ((/=) :: Int -> Int -> Bool)antireflexivity ((>) :: Int -> Int -> Bool)antireflexivityOnArbitrary ((<) :: Int -> Int -> Bool)antireflexivityOnArbitrary ((/=) :: Int -> Int -> Bool)antireflexivityOnArbitrary ((>) :: Int -> Int -> Bool)Symmetry
Symmetric(\prec)
\quad\equiv\quad
\forall a, b: (a \prec b) \Leftrightarrow (b \prec a)
symmetry ((==) :: Int -> Int -> Bool)symmetry ((/=) :: Int -> Int -> Bool)symmetryOnArbitrary ((==) :: Int -> Int -> Bool)symmetryOnArbitrary ((/=) :: Int -> Int -> Bool)Properties of operations
0 declarationsIdentity element
Left Identity
LeftIdentity(\star, \doteq, b)
\quad\equiv\quad
\forall a: (b \star a) \doteq a
leftIdentity (flip ((^) :: Int -> Int -> Int)) 1leftIdentityOnArbitrary (flip ((^) :: Int -> Int -> Int)) 1Right Identity
RightIdentity(\star, \doteq, b)
\quad\equiv\quad
\forall a: (a \star b) \doteq a
rightIdentity ((^) :: Int -> Int -> Int) 1rightIdentityOnArbitrary ((^) :: Int -> Int -> Int) 1Identity
Identity(\star, \doteq, b)
\quad\equiv\quad
LeftIdentity(\star, \doteq, b) \wedge RightIdentity(\star, \doteq, b)
identity ((*) :: Int -> Int -> Int) 1identity ((+) :: Int -> Int -> Int) 0identityOnArbitrary ((*) :: Int -> Int -> Int) 1identityOnArbitrary ((+) :: Int -> Int -> Int) 0Associativity
Associative(\star)
\quad\equiv\quad
\forall a, b, c:
(a \star b) \star c = a \star (b \star c)
associative ((*) :: Int -> Int -> Int)associative ((+) :: Int -> Int -> Int)associativeOnArbitrary ((*) :: Int -> Int -> Int)associativeOnArbitrary ((+) :: Int -> Int -> Int)Commutativity
Commutative(\star)
\quad\equiv\quad
\forall a, b:
a \star b = b \star a
commutative ((+) :: Int -> Int -> Int)commutative ((*) :: Int -> Int -> Int)commutativeOnArbitrary ((+) :: Int -> Int -> Int)commutativeOnArbitrary ((*) :: Int -> Int -> Int)commutativeOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> a) -> Property
Show and Read properties
3 declarationsStandard test spec for properties of Show and Read instances for valid values
Example usage:
showReadSpec @IntStandard test spec for properties of Show and Read instances for arbitrary values
Example usage:
showReadSpecOnArbitrary @DoubleStandard test spec for properties of Show and Read instances for values generated by a custom generator
Example usage:
showReadSpecOnGen ((* 2) <$> genValid @Int) "even" (const [])Eq properties
3 declarationsStandard test spec for properties of Eq instances for valid values
Example usage:
eqSpec @IntStandard test spec for properties of Eq instances for arbitrary values
Example usage:
eqSpecOnArbitrary @IntStandard test spec for properties of Eq instances for values generated by a given generator (and name for that generator).
Example usage:
eqSpecOnGen ((* 2) <$> genValid @Int) "even"Ord properties
3 declarationsStandard test spec for properties of Ord instances for values generated by a given generator (and name for that generator).
Example usage:
ordSpecOnGen ((* 2) <$> genValid @Int) "even"Standard test spec for properties of Ord instances for valid values
Example usage:
ordSpec @IntStandard test spec for properties of Ord instances for arbitrary values
Example usage:
ordSpecOnArbitrary @IntMonoid properties
3 declarationsStandard test spec for properties of Monoid instances for valid values
Example usage:
monoidSpec @[Int]Standard test spec for properties of Monoid instances for arbitrary values
Example usage:
monoidSpecOnArbitrary @[Int]Standard test spec for properties of Monoid instances for values generated by a given generator (and name for that generator).
Example usage:
monoidSpecOnGen (pure "a") "singleton list of 'a'"Functor properties
3 declarationsStandard test spec for properties of Functor instances for values generated with GenValid instances
Example usage:
functorSpecOnArbitrary @[]functorSpecOnArbitrary :: (Eq (f Int), Show (f Int), Functor f, Typeable f, Arbitrary (f Int)) => SpecStandard test spec for properties of Functor instances for values generated with Arbitrary instances
Example usage:
functorSpecOnArbitrary @[]Standard test spec for properties of Functor instances for values generated by given generators (and names for those generator).
Example usage:
functorSpecOnGens
@[]
@Int
(pure 4) "four"
(genListOf $ pure 5) "list of fives"
((+) <$> genValid) "additions"
((*) <$> genValid) "multiplications"Applicative properties
3 declarationsapplicativeSpec :: (Eq (f Int), Show (f Int), Applicative f, Typeable f, GenValid (f Int)) => SpecStandard test spec for properties of Applicative instances for values generated with GenValid instances
Example usage:
applicativeSpecOnArbitrary @[]applicativeSpecOnArbitrary :: (Eq (f Int), Show (f Int), Applicative f, Typeable f, Arbitrary (f Int)) => SpecStandard test spec for properties of Applicative instances for values generated with Arbitrary instances
Example usage:
applicativeSpecOnArbitrary @[]Standard test spec for properties of Applicative instances for values generated by given generators (and names for those generator).
Unless you are building a specific regression test, you probably want to use the other applicativeSpec functions.
Example usage:
applicativeSpecOnGens
@Maybe
@String
(pure "ABC")
"ABC"
(Just <$> pure "ABC")
"Just an ABC"
(pure Nothing)
"purely Nothing"
((++) <$> genValid)
"prepends"
(pure <$> ((++) <$> genValid))
"prepends in a Just"
(pure <$> (flip (++) <$> genValid))
"appends in a Just"Monad properties
3 declarationsStandard test spec for properties of Monad instances for values generated with GenValid instances
Example usage:
monadSpec @[]monadSpecOnArbitrary :: (Eq (f Int), Show (f Int), Monad f, Typeable f, Arbitrary (f Int)) => SpecStandard test spec for properties of Monad instances for values generated with Arbitrary instances
Example usage:
monadSpecOnArbitrary @[]Standard test spec for properties of Monad instances for values generated by given generators (and names for those generator).
Example usage:
monadSpecOnGens
@[]
@Int
(pure 4)
"four"
(genListOf $ pure 5)
"list of fives"
(genListOf $ pure 6)
"list of sixes"
((*) <$> genValid)
"factorisations"
(pure $ \a -> [a])
"singletonisation"
(pure $ \a -> [a])
"singletonisation"
(pure $ pure (+ 1))
"increment in list"Re-exports
81 declarationsA class of types that have additional invariants defined upon them
Methods
validate :: a -> Validation
Instances79Validity, …
Validity KeyDefined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphanValidity ValueDefined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphanA Value is valid if the recursive components are valid.
Validity UnionDefined in autodocodec-0.5.0.0 · Autodocodec.CodecValidity JSONSchemaDefined in autodocodec-schema-0.2.0.1 · Autodocodec.SchemaValidity KeyRequirementDefined in autodocodec-schema-0.2.0.1 · Autodocodec.SchemaValidity ObjectSchemaDefined in autodocodec-schema-0.2.0.1 · Autodocodec.SchemaValidity ByteStringDefined in validity-bytestring-0.4.1.1 · Data.Validity.ByteString · orphanA
ByteStringis NOT trivially valid.The offset and the length both need to be positive. Note that the length does not need to be greater than, or equal to, the offset.
TODO there's nothing we can do about the foreign pointer, I think?
Validity ByteStringDefined in validity-bytestring-0.4.1.1 · Data.Validity.ByteString · orphanA lazy
ByteStringis valid according to its chunks.Validity ShortByteStringDefined in validity-bytestring-0.4.1.1 · Data.Validity.ByteString · orphanTrivially valid
My guess is that short bytestrings are not trivially valid but there is no way to access the internals.
Validity IntegerDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Integer is not trivially valid under the hood, but instantiating Validity correctly would force validity to depend on a specific (big integer library
integer-gmpversusinteger-simple). This is rather impractical so for the time being we have opted for assuming that an Integer is always valid. Even though this is not technically sound, it is good enough for now.Validity NaturalDefined in validity-0.12.1.0 · Data.ValidityValid according to isValidNatural
Validity Int16Defined in validity-0.12.1.0 · Data.ValidityValidity Int32Defined in validity-0.12.1.0 · Data.ValidityValidity Int64Defined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity Int8Defined in validity-0.12.1.0 · Data.ValidityValidity Word16Defined in validity-0.12.1.0 · Data.ValidityValidity Word32Defined in validity-0.12.1.0 · Data.ValidityValidity Word64Defined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity Word8Defined in validity-0.12.1.0 · Data.ValidityValidity BoolDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity CharDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity DoubleDefined in validity-0.12.1.0 · Data.ValidityTrivially valid:
Validity FloatDefined in validity-0.12.1.0 · Data.ValidityTrivially valid:
Validity IntDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity OrderingDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity WordDefined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity ArgDefined in opt-env-conf-0.11.0.0 · OptEnvConf.ArgsValidity ArgsDefined in opt-env-conf-0.11.0.0 · OptEnvConf.ArgsValidity DashedDefined in opt-env-conf-0.11.0.0 · OptEnvConf.ArgsValidity EnvMapDefined in opt-env-conf-0.11.0.0 · OptEnvConf.EnvMapValidity ChunkDefined in safe-coloured-text-0.3.0.2 · Text.Colour.ChunkValidity ColourDefined in safe-coloured-text-0.3.0.2 · Text.Colour.ChunkValidity BlinkingDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity CSIDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity ColourIntensityDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity ConsoleIntensityDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity ConsoleLayerDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity SGRDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity TerminalColourDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity UnderliningDefined in safe-coloured-text-0.3.0.2 · Text.Colour.CodeValidity TableDefined in safe-coloured-text-layout-0.2.0.1 · Text.Colour.LayoutValidity TableBackgroundDefined in safe-coloured-text-layout-0.2.0.1 · Text.Colour.LayoutValidity ScientificDefined in validity-scientific-0.2.0.3 · Data.Validity.Scientific · orphanA Scientific is valid according to the validity of its coefficient and exponent.
Validity TextDefined in validity-text-0.3.1.3 · Data.Validity.Text · orphanA text is valid if the internal structure is consistent.
Validity TextDefined in validity-text-0.3.1.3 · Data.Validity.Text · orphanA lazy text value is valid if all the internal chunks are valid and nonempty
Validity ValidationChainDefined in validity-0.12.1.0 · Data.ValidityValidity ()Defined in validity-0.12.1.0 · Data.ValidityTrivially valid
Validity a => Validity (Bounds a)Defined in autodocodec-0.5.0.0 · Autodocodec.CodecValidity a => Validity (First a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Last a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Tree a)Defined in validity-containers-0.5.0.5 · Data.Validity.Tree · orphanValidity a => Validity (NonEmpty a)Defined in validity-0.12.1.0 · Data.ValidityA nonempty list is valid if all the elements are valid.
See the instance for 'Validity [a]' for more information.
Validity a => Validity (Identity a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (First a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Last a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Dual a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Maybe a)Defined in validity-0.12.1.0 · Data.ValidityA Maybe thing is valid if the thing inside is valid or it's nothing It makes sense to assume that Nothing is valid. If Nothing wasn't valid, you wouldn't have used a Maybe in the datastructure.
Validity a => Validity (Tomb a)Defined in opt-env-conf-0.11.0.0 · OptEnvConf.ArgsValidity a => Validity (Vector a)Defined in validity-vector-0.2.0.3 · Data.Validity.Vector · orphanA
Vectorof things is valid if all the elements are valid.TODO make a more comprehensive instance that looks at implementation and the underlying
ArrayValidity a => Validity [a]Defined in validity-0.12.1.0 · Data.ValidityA list of things is valid if all of the things are valid.
This means that the empty list is considered valid. If the empty list should not be considered valid as part of your custom data type, make sure to write a custom
Validity instanceValidity v => Validity (KeyMap v)Defined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphanValidity v => Validity (IntMap v)Defined in validity-containers-0.5.0.5 · Data.Validity.IntMap · orphanValidity v => Validity (Seq v)Defined in validity-containers-0.5.0.5 · Data.Validity.Sequence · orphanA Sequence of things is valid if all the elements are valid.
Validity v => Validity (HashSet v)Defined in validity-unordered-containers-0.2.0.3 · Data.Validity.HashSet · orphanA HashSet of things is valid if all the elements are valid and the underlying
HashMapis valid.(Storable e, Validity e) => Validity (Vector e)Defined in validity-vector-0.2.0.3 · Data.Validity.Vector · orphan(Ord v, Validity v) => Validity (Set v)Defined in validity-containers-0.5.0.5 · Data.Validity.Set · orphan(Validity a, Ord a, Num a, Integral a) => Validity (Ratio a)Defined in validity-0.12.1.0 · Data.ValidityValid if the contained numbers are valid and the denominator is strictly positive.
(Unbox e, Validity e) => Validity (Vector e)Defined in validity-vector-0.2.0.3 · Data.Validity.Vector · orphanHasResolution a => Validity (Fixed a)Defined in validity-0.12.1.0 · Data.ValidityValid according to the contained Integer.
(Show k, Ord k, Validity k, Validity v) => Validity (Map k v)Defined in validity-containers-0.5.0.5 · Data.Validity.Map · orphan(Validity a, Validity b) => Validity (Either a b)Defined in validity-0.12.1.0 · Data.ValidityAny Either of things is valid if the contents are valid in either of the cases.
(Validity a, Validity b) => Validity (a, b)Defined in validity-0.12.1.0 · Data.ValidityAny tuple of things is valid if both of its elements are valid
(Validity k, Validity v) => Validity (HashMap k v)Defined in validity-unordered-containers-0.2.0.3 · Data.Validity.HashMap · orphanValidity (f a) => Validity (Alt f a)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
Validity a => Validity (Const a b)Defined in validity-0.12.1.0 · Data.ValidityValid values the same as it's base type:
(Validity a, Validity b, Validity c) => Validity (a, b, c)Defined in validity-0.12.1.0 · Data.ValidityAny triple of things is valid if all three of its elements are valid
(Validity a, Validity b, Validity c, Validity d) => Validity (a, b, c, d)Defined in validity-0.12.1.0 · Data.ValidityAny quadruple of things is valid if all four of its elements are valid
(Validity a, Validity b, Validity c, Validity d, Validity e) => Validity (a, b, c, d, e)Defined in validity-0.12.1.0 · Data.ValidityAny quintuple of things is valid if all five of its elements are valid
(Validity a, Validity b, Validity c, Validity d, Validity e, Validity f) => Validity (a, b, c, d, e, f)Defined in validity-0.12.1.0 · Data.ValidityAny sextuple of things is valid if all six of its elements are valid
The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:
- Right identity
- Left identity
- Associativity
(
law)
- Concatenation
You can alternatively define mconcat instead of mempty, in which case the laws are:
- Unit
- Multiplication
- Subclass
The method names refer to the monoid of lists under concatenation, but there are many other instances.
Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Data.Semigroup.Sum and Data.Semigroup.Product.
NOTE: Semigroup is a superclass of Monoid since base-4.11.0.0.
Methods
mempty :: aIdentity of mappend
Examples
Example1 expression "Hello world" <> mempty"Hello world"
Example1 expression mempty <> [1, 2, 3][1,2,3]
mappend :: a -> a -> aAn associative operation
NOTE: This method is redundant and has the default implementation
mappend = (<>)since base-4.11.0.0. Should it be implemented manually, since mappend is a synonym for (<>), it is expected that the two functions are defined the same way. In a future GHC release mappend will be removed from Monoid.mconcat :: [a] -> aFold a list using the monoid.
For most types, the default definition for mconcat will be used, but the function is included in the class definition so that an optimized version can be provided for specific types.
Example1 expression mconcat ["Hello", " ", "Haskell", "!"]"Hello Haskell!"
Instances123Monoid, …
Monoid SeriesDefined in aeson-2.2.3.0 · Data.Aeson.Encoding.InternalMonoid KeyDefined in aeson-2.2.3.0 · Data.Aeson.KeyMonoid MoreDefined in attoparsec-0.14.4 · Data.Attoparsec.Internal.TypesMonoid ByteArrayDefined in base-4.20.2.0 · Data.Array.ByteMonoid PokeDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.WriteMonoid WriteDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.WriteMonoid BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalMonoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeMonoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.InternalMonoid ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalMonoid IntSetDefined in containers-0.7 · Data.IntSet.InternalMonoid AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalMonoid AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalMonoid EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesMonoid EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesMonoid LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Typesmappendtakes the longer of two lifetimes.Monoid ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.ContextMonoid OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid OsStringDefined in os-string-2.0.7 · System.OsString.Internal.Types"String-Concatenation" for OsString. This is not the same as
(</>).Monoid PosixStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesMonoid WindowsStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesMonoid DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJMonoid ElementDefined in svg-builder-0.1.1 · Graphics.Svg.CoreMonoid TestSuiteStatsDefined in sydtest-0.22.0.0 · Test.Syd.SpecDefMonoid TermOutputDefined in terminfo-0.4.1.7 · System.Console.Terminfo.BaseMonoid TextDefined in text-2.1.3 · Data.Text · orphanMonoid BuilderDefined in text-2.1.3 · Data.Text.Internal.BuilderMonoid TextDefined in text-2.1.3 · Data.Text.Lazy · orphanMonoid StrictTextBuilderDefined in text-2.1.3 · Data.Text.Internal.StrictBuilderMonoid ShortTextDefined in text-short-0.1.6 · Data.Text.Short.InternalMonoid CalendarDiffDaysDefined in time-1.12.2 · Data.Time.Calendar.CalendarDiffDaysAdditive
Monoid CalendarDiffTimeDefined in time-1.12.2 · Data.Time.LocalTime.Internal.CalendarDiffTimeAdditive
Monoid StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonMonoid StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonMonoid ValidationDefined in validity-0.12.1.0 · Data.ValidityMonoid ()Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid (KeyMap v)Defined in aeson-2.2.3.0 · Data.Aeson.KeyMapMonoid (IResult a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalMonoid (Parser a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalMonoid (Result a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalMonoid (Comparison a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (Predicate a)Defined in base-4.20.2.0 · Data.Functor.ContravariantMonoid (PutM ())Defined in binary-0.8.9.3 · Data.Binary.PutMonoid (IntMap a)Defined in containers-0.7 · Data.IntMap.InternalMonoid (Seq a)Defined in containers-0.7 · Data.Sequence.InternalMonoid (MergeSet a)Defined in containers-0.7 · Data.Set.InternalMonoid (DList a)Defined in dlist-1.0 · Data.DList.InternalMonoid (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidMonoid (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidMonoid (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalMonoid (Builder f)Defined in opt-env-conf-0.11.0.0 · OptEnvConf.SettingMonoid (Doc a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJMonoid (Array a)Defined in primitive-0.9.1.0 · Data.Primitive.ArrayMonoid (PrimArray a)Defined in primitive-0.9.1.0 · Data.Primitive.PrimArrayMonoid (SmallArray a)Defined in primitive-0.9.1.0 · Data.Primitive.SmallArrayMonoid (Validity k)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal.DebugMonoid (Vector a)Defined in vector-0.13.2.0 · Data.VectorMonoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StrictMonoid (YamlParser a)Defined in yaml-0.11.11.2 · Data.Yaml.ParserMonoid [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid a => Monoid (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncMonoid a => Monoid (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentityMonoid a => Monoid (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdMonoid a => Monoid (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalMonoid a => Monoid (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid a => Monoid (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxMonoid a => Monoid (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid m => Monoid (WrappedMonoid m)Defined in base-4.20.2.0 · Data.SemigroupMonoid p => Monoid (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup a => Monoid (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseLift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup
Smay be turned into a monoid simply by adjoining an elementenot inSand defininge*e = eande*s = s = s*efor alls ∈ S."Since 4.11.0: constraint on inner
avalue generalised from Monoid to Semigroup.Semigroup a => Monoid (Maybe a)Defined in strict-0.5.1 · Data.Strict.MaybeBits a => Monoid (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Monoid (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => Monoid (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.FiniteBits a => Monoid (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.Storable a => Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StorableNum a => Monoid (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalNum a => Monoid (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalOrd a => Monoid (Set a)Defined in containers-0.7 · Data.Set.InternalOrd a => Monoid (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsOrd a => Monoid (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsHashable a => Monoid (HashSet a)Defined in unordered-containers-0.2.21 · Data.HashSet.InternalPrim a => Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.PrimitiveUnbox a => Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed · orphan(Semigroup a, Monoid a) => Monoid (Concurrently a)Defined in async-2.2.5 · Control.Concurrent.Async.Internal(Generic a, Monoid (Rep a ())) => Monoid (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Ord a, Bounded a) => Monoid (Max a)Defined in base-4.20.2.0 · Data.Semigroup(Ord a, Bounded a) => Monoid (Min a)Defined in base-4.20.2.0 · Data.SemigroupMonad m => Monoid (ZeptoT m a)Defined in attoparsec-0.14.4 · Data.Attoparsec.ZeptoMonoid (Parser i a)Defined in attoparsec-0.14.4 · Data.Attoparsec.Internal.TypesMonoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxyMonoid (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonoid a => Monoid (Op a b)Defined in base-4.20.2.0 · Data.Functor.Contravariantmempty @(Op a b)without newtypes ismempty @(b->a)=_ -> mempty.mempty :: Op a b mempty = Op _ -> memptyMonoid a => Monoid (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.STMonoid b => Monoid (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseOrd k => Monoid (Map k v)Defined in containers-0.7 · Data.Map.InternalHashable k => Monoid (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal(Monoid a, Monoid b) => Monoid (Pair a b)Defined in strict-0.5.1 · Data.Strict.Tuple(Monoid a, Monoid b) => Monoid (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Semigroup a, Monoid a) => Monoid (ConcurrentlyE e a)Defined in async-2.2.5 · Control.Concurrent.Async.Internal(Repeat f, Monoid a) => Monoid (Zippy f a)Defined in semialign-1.3.1 · Data.ZipAlternative f => Monoid (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative f => Monoid (Traversed a f)Defined in indexed-traversable-0.1.4 · WithIndexMonad m => Monoid (Sequenced a m)Defined in indexed-traversable-0.1.4 · WithIndexMonoid (f p) => Monoid (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonoid a => Monoid (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstMonoid a => Monoid (Constant a b)Defined in transformers-0.6.1.1 · Data.Functor.Constant(Biapplicative bi, Monoid a, Monoid b) => Monoid (Biap bi a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biap(Applicative f, Monoid a) => Monoid (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid(Monoid a, Monoid b, Monoid c) => Monoid (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Semigroup a, Monoid a) => Monoid (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedMonad m => Monoid (ConduitT i o m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitMonoid c => Monoid (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Monoid (f a), Monoid (g a)) => Monoid (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product(Monoid (f p), Monoid (g p)) => Monoid ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Monoid a, Monoid b, Monoid c, Monoid d) => Monoid (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Monoid a, Semigroup (ParsecT s u m a)) => Monoid (ParsecT s u m a)Defined in parsec-3.1.18.0 · Text.Parsec.PrimMonoid (f (g a)) => Monoid (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.ComposeMonoid (f (g p)) => Monoid ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonoid (f p) => Monoid (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Monoid a, Monoid b, Monoid c, Monoid d, Monoid e) => Monoid (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonad m => Monoid (Pipe l i o u m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.Pipe
A class of types for which valid values can be generated to be valid.
How to instantiate GenValid
Step 1: Try to instantiate GenValid without overriding any functions. It is possible that, if few values are valid or if validity checking is expensive, the resulting generator is too slow. In that case, go to Step 2.
Step 2: Consider using genValidStructurallyWithoutExtraChecking and shrinkValidStructurallyWithoutExtraFiltering to speed up generation. This only works if your type has a derived or trivial Validity instance.
Step 3: If that still is not fast enough, consider writing your own generator and shrinking function. Make sure to generate any possible valid value, but only valid values.
A note about Arbitrary
If you also write Arbitrary instances for GenValid types, it may be
best to simply use
instance Arbitrary A where
arbitrary = genValid
shrink = shrinkValidMethods
genValid :: Gen aGenerate a valid datum, this should cover all possible valid values in the type
The default implementation is as follows:
genValid = genValidStructurallyTo speed up testing, it may be a good idea to implement this yourself. If you do, make sure that it is possible to generate all possible valid data, otherwise your testing may not cover all cases.
shrinkValid :: a -> [a]Shrink a valid value.
The default implementation is as follows:
shrinkValid = shrinkValidStructurallyIt is important that this shrinking function only shrinks values to valid values. If shrinkValid ever shrinks a value to an invalid value, the test that is being shrunk for might fail for a different reason than for the reason that it originally failed. This would lead to very confusing error messages.
Instances36GenValid, …
GenValid IntegerDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid NaturalDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Int16Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Int32Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Int64Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Int8Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Word16Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Word32Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Word64Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid Word8Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid BoolDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid CharDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid DoubleDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid FloatDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid IntDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid OrderingDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid WordDefined in genvalidity-1.1.1.0 · Data.GenValidityGenValid ()Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (First a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Last a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (NonEmpty a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Identity a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (First a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Last a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Dual a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Maybe a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid [a]Defined in genvalidity-1.1.1.0 · Data.GenValidity(Integral a, Num a, Ord a, GenValid a) => GenValid (Ratio a)Defined in genvalidity-1.1.1.0 · Data.GenValidityHasResolution a => GenValid (Fixed a)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GenValid a, GenValid b) => GenValid (Either a b)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GenValid a, GenValid b) => GenValid (a, b)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid (f a) => GenValid (Alt f a)Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GenValid (Const a b)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GenValid a, GenValid b, GenValid c) => GenValid (a, b, c)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GenValid a, GenValid b, GenValid c, GenValid d) => GenValid (a, b, c, d)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GenValid a, GenValid b, GenValid c, GenValid d, GenValid e) => GenValid (a, b, c, d, e)Defined in genvalidity-1.1.1.0 · Data.GenValidity
Validate a given value
This function will return a nice error if the value is invalid. It will return the original value in Right if it was valid, as evidence that it has been validated.
Check whether a value is valid.
The class of semigroups (types with an associative binary operation).
Instances should satisfy the following:
You can alternatively define sconcat instead of (<>), in which case the laws are:
Methods
(<>) :: a -> a -> ainfixr 6An associative operation.
Examples
Example1 expression [1,2,3] <> [4,5,6][1,2,3,4,5,6]
Example1 expression Just [1, 2, 3] <> Just [4, 5, 6]Just [1,2,3,4,5,6]
Example1 expression putStr "Hello, " <> putStrLn "World!"Hello, World!
sconcat :: NonEmpty a -> aReduce a non-empty list with <>
The default definition should be sufficient, but this can be overridden for efficiency.
Examples
For the following examples, we will assume that we have:
Example1 expression import Data.List.NonEmpty (NonEmpty (..))Example1 expression sconcat $ "Hello" :| [" ", "Haskell", "!"]"Hello Haskell!"
Example1 expression sconcat $ Just [1, 2, 3] :| [Nothing, Just [4, 5, 6]]Just [1,2,3,4,5,6]
Example1 expression sconcat $ Left 1 :| [Right 2, Left 3, Right 4]Right 2
stimes :: Integral b => b -> a -> aRepeat a value
ntimes.The default definition will raise an exception for a multiplier that is
<= 0. This may be overridden with an implementation that is total. For monoids it is preferred to usestimesMonoid.By making this a member of the class, idempotent semigroups and monoids can upgrade this to execute in
\mathcal{O}(1)by pickingstimes = stimesIdempotentorstimes = stimesIdempotentMonoidrespectively.Examples
Example1 expression stimes 4 [1][1,1,1,1]
Example1 expression stimes 5 (putStr "hi!")hi!hi!hi!hi!hi!
Example1 expression stimes 3 (Right ":)")Right ":)"
Instances144Semigroup, …
Semigroup SeriesDefined in aeson-2.2.3.0 · Data.Aeson.Encoding.InternalSemigroup KeyDefined in aeson-2.2.3.0 · Data.Aeson.KeySemigroup MoreDefined in attoparsec-0.14.4 · Data.Attoparsec.Internal.TypesSemigroup ByteArrayDefined in base-4.20.2.0 · Data.Array.ByteSemigroup PokeDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.WriteSemigroup WriteDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.WriteSemigroup BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.InternalSemigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.TypeSemigroup ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.InternalSemigroup ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.InternalSemigroup IntSetDefined in containers-0.7 · Data.IntSet.InternalSemigroup VoidDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.TypesSemigroup ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.ContextSemigroup OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup OsStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup PosixStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup WindowsStringDefined in os-string-2.0.7 · System.OsString.Internal.TypesSemigroup DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJSemigroup ElementDefined in svg-builder-0.1.1 · Graphics.Svg.CoreSemigroup TestSuiteStatsDefined in sydtest-0.22.0.0 · Test.Syd.SpecDefSemigroup TermOutputDefined in terminfo-0.4.1.7 · System.Console.Terminfo.BaseSemigroup TextDefined in text-2.1.3 · Data.Text · orphanBeware:
stimeswill crash if the given number does not fit into anInt.Semigroup BuilderDefined in text-2.1.3 · Data.Text.Internal.BuilderSemigroup TextDefined in text-2.1.3 · Data.Text.Lazy · orphanSemigroup StrictTextBuilderDefined in text-2.1.3 · Data.Text.Internal.StrictBuilderConcatenation of StrictBuilder is right-biased: the right builder will be run first. This allows a builder to run tail-recursively when it was accumulated left-to-right.
Semigroup ShortTextDefined in text-short-0.1.6 · Data.Text.Short.InternalSemigroup CalendarDiffDaysDefined in time-1.12.2 · Data.Time.Calendar.CalendarDiffDaysAdditive
Semigroup CalendarDiffTimeDefined in time-1.12.2 · Data.Time.LocalTime.Internal.CalendarDiffTimeAdditive
Semigroup StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the flags.
Semigroup StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.CommonORs the masks.
Semigroup ValidationDefined in validity-0.12.1.0 · Data.ValiditySemigroup MergedValueDefined in yaml-0.11.11.2 · Data.Yaml.ConfigSemigroup ()Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonoid m => Semigroup (WrappedMonoid m)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (KeyMap v)Defined in aeson-2.2.3.0 · Data.Aeson.KeyMapSemigroup (IResult a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalSemigroup (Parser a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalSemigroup (Result a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.InternalSemigroup (FromMaybe b)Defined in base-4.20.2.0 · Data.Foldable1Semigroup (NonEmptyDList a)Defined in base-4.20.2.0 · Data.Foldable1Semigroup (Comparison a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (Predicate a)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup (First a)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (Last a)Defined in base-4.20.2.0 · Data.SemigroupSemigroup (PutM ())Defined in binary-0.8.9.3 · Data.Binary.PutSemigroup (IntMap a)Defined in containers-0.7 · Data.IntMap.InternalSemigroup (Seq a)Defined in containers-0.7 · Data.Sequence.InternalSemigroup (MergeSet a)Defined in containers-0.7 · Data.Set.InternalSemigroup (DNonEmpty a)Defined in dlist-1.0 · Data.DList.DNonEmpty.InternalSemigroup (DList a)Defined in dlist-1.0 · Data.DList.InternalSemigroup (NonEmpty a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidSemigroup (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.MonoidSemigroup (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup (FromMaybe b)Defined in indexed-traversable-0.1.4 · WithIndexSemigroup (Builder f)Defined in opt-env-conf-0.11.0.0 · OptEnvConf.SettingSemigroup (Doc a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJSemigroup (Array a)Defined in primitive-0.9.1.0 · Data.Primitive.ArraySemigroup (PrimArray a)Defined in primitive-0.9.1.0 · Data.Primitive.PrimArraySemigroup (SmallArray a)Defined in primitive-0.9.1.0 · Data.Primitive.SmallArraySemigroup (Validity k)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal.DebugSemigroup (Vector a)Defined in vector-0.13.2.0 · Data.VectorSemigroup (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StrictSemigroup (YamlParser a)Defined in yaml-0.11.11.2 · Data.Yaml.ParserSemigroup [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (Concurrently a)Defined in async-2.2.5 · Control.Concurrent.Async.InternalOnly defined by
asyncforbase >= 4.9Semigroup a => Semigroup (JoinWith a)Defined in base-4.20.2.0 · Data.Foldable1Semigroup a => Semigroup (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.SyncSemigroup a => Semigroup (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.IdentitySemigroup a => Semigroup (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.OrdSemigroup a => Semigroup (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalSemigroup a => Semigroup (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup a => Semigroup (JoinWith a)Defined in semigroupoids-6.0.1 · Data.Semigroup.FoldableSemigroup a => Semigroup (Maybe a)Defined in strict-0.5.1 · Data.Strict.MaybeSemigroup a => Semigroup (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.SyntaxSemigroup a => Semigroup (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup p => Semigroup (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsBits a => Semigroup (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsBits a => Semigroup (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsFiniteBits a => Semigroup (Iff a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.BitsThis constraint is arguably too strong. However, as some types (such as
Natural) have undefined complement, this is the only safe choice.Storable a => Semigroup (Vector a)Defined in vector-0.13.2.0 · Data.Vector.StorableNum a => Semigroup (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalNum a => Semigroup (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalOrd a => Semigroup (Max a)Defined in base-4.20.2.0 · Data.SemigroupOrd a => Semigroup (Min a)Defined in base-4.20.2.0 · Data.SemigroupOrd a => Semigroup (Intersection a)Defined in containers-0.7 · Data.Set.InternalOrd a => Semigroup (Set a)Defined in containers-0.7 · Data.Set.InternalOrd a => Semigroup (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsOrd a => Semigroup (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.UtilsHashable a => Semigroup (HashSet a)Defined in unordered-containers-0.2.21 · Data.HashSet.InternalPrim a => Semigroup (Vector a)Defined in vector-0.13.2.0 · Data.Vector.PrimitiveUnbox a => Semigroup (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Unboxed · orphan(Semigroup mono, GrowingAppend mono) => Semigroup (NonNull mono)Defined in mono-traversable-1.0.21.0 · Data.NonNull(Generic a, Semigroup (Rep a ())) => Semigroup (Generically a)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsMonad m => Semigroup (ZeptoT m a)Defined in attoparsec-0.14.4 · Data.Attoparsec.ZeptoSemigroup (Parser i a)Defined in attoparsec-0.14.4 · Data.Attoparsec.Internal.TypesSemigroup (Either a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.EitherSemigroup (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.ProxySemigroup (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (V1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (Either a b)Defined in strict-0.5.1 · Data.Strict.EitherSemigroup a => Semigroup (ConcurrentlyE e a)Defined in async-2.2.5 · Control.Concurrent.Async.InternalEither the combination of the successful results, or the first failure.
Semigroup a => Semigroup (Op a b)Defined in base-4.20.2.0 · Data.Functor.ContravariantSemigroup a => Semigroup (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.STSemigroup b => Semigroup (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseOrd k => Semigroup (Map k v)Defined in containers-0.7 · Data.Map.InternalHashable k => Semigroup (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.InternalAlt f => Semigroup (Alt_ f a)Defined in semigroupoids-6.0.1 · Data.Semigroup.FoldableApply f => Semigroup (Act f a)Defined in semigroupoids-6.0.1 · Data.Semigroup.BifoldableApply f => Semigroup (Act f a)Defined in semigroupoids-6.0.1 · Data.Semigroup.Foldable(Semigroup a, Semigroup b) => Semigroup (These a b)Defined in strict-0.5.1 · Data.Strict.These(Semigroup a, Semigroup b) => Semigroup (Pair a b)Defined in strict-0.5.1 · Data.Strict.Tuple(Semigroup a, Semigroup b) => Semigroup (These a b)Defined in these-1.2.1 · Data.These(Semigroup a, Semigroup b) => Semigroup (a, b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base(Zip f, Semigroup a) => Semigroup (Zippy f a)Defined in semialign-1.3.1 · Data.ZipAlternative f => Semigroup (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.InternalApplicative f => Semigroup (Traversed a f)Defined in indexed-traversable-0.1.4 · WithIndexMonad m => Semigroup (Sequenced a m)Defined in indexed-traversable-0.1.4 · WithIndexSemigroup (f p) => Semigroup (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup a => Semigroup (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.ConstSemigroup a => Semigroup (Tagged s a)Defined in tagged-0.8.9 · Data.TaggedSemigroup a => Semigroup (Constant a b)Defined in transformers-0.6.1.1 · Data.Functor.Constant(Biapplicative bi, Semigroup a, Semigroup b) => Semigroup (Biap bi a b)Defined in bifunctors-5.6.2 · Data.Bifunctor.Biap(Applicative f, Semigroup a) => Semigroup (Ap f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid(Semigroup a, Semigroup b, Semigroup c) => Semigroup (a, b, c)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonad m => Semigroup (ConduitT i o m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.ConduitSemigroup a => Semigroup (ParsecT s u m a)Defined in parsec-3.1.18.0 · Text.Parsec.PrimThe Semigroup instance for ParsecT is used to append the result of several parsers, for example:
(many $ chara) <> (many $ charb)The above will parse a string like
"aabbb"and return a successful parse result"aabbb". Compare against the below which will produce a result of"bbb"for the same input:(many $ chara) >> (many $ charb) (many $ chara) *> (many $ charb)Semigroup c => Semigroup (K1 i c p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup (f a), Semigroup (g a)) => Semigroup (Product f g a)Defined in base-4.20.2.0 · Data.Functor.Product(Semigroup (f p), Semigroup (g p)) => Semigroup ((:*:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup a, Semigroup b, Semigroup c, Semigroup d) => Semigroup (a, b, c, d)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseSemigroup (f (g a)) => Semigroup (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.ComposeSemigroup (f (g p)) => Semigroup ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.GenericsSemigroup (f p) => Semigroup (M1 i c f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics(Semigroup a, Semigroup b, Semigroup c, Semigroup d, Semigroup e) => Semigroup (a, b, c, d, e)Defined in ghc-internal-9.1003.0 · GHC.Internal.BaseMonad m => Semigroup (Pipe l i o u m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.Pipe
'arbPartition n' generates a list ls such that 'sum ls' equals n, approximately.
See genFloatX
See genFloatX
Generate floating point numbers smartly:
Some denormalised
Some around zero
Some around the bounds
Some by encoding an Integer and an Int to a floating point number.
Some accross the entire range
Mostly uniformly via the bitrepresentation
The function parameter is to go from the bitrepresentation to the floating point value.
Generate Int, Int8, Int16, Int32 and Int64 values smartly.
Some at the border
Some around zero
Mostly uniformly
A version of listOf that takes size into account more accurately.
This generator distributes the size that is is given among the values in the list that it generates.
A version of genNonEmptyOf that returns a list instead of a NonEmpty.
'genSplit a' generates a tuple '(b, c)' such that 'b + c' equals a.
'genSplit3 a' generates a triple '(b, c, d)' such that 'b + c + d' equals a.
'genSplit4 a' generates a quadruple '(b, c, d, e)' such that 'b + c + d + e' equals a.
'genSplit5 a' generates a quintuple '(b, c, d, e, f)' such that 'b + c + d + e + f' equals a.
'genSplit6 a' generates a sextuple '(b, c, d, e, f, g)' such that 'b + c + d + e + f + g' equals a.
'genSplit7 a' generates a septtuple '(b, c, d, e, f, g)' such that 'b + c + d + e + f + g' equals a.
'genSplit8 a' generates a octtuple '(b, c, d, e, f, g, h)' such that 'b + c + d + e + f + g + h' equals a.
Generate Word, Word8, Word16, Word32 and Word64 values smartly.
Some at the border
Some around zero
Mostly uniformly
Lift a shrinker function into a maybe
Like shrinkTuple, but for quadruples
Turn a shrinking function into a function that shrinks tuples.
Turn a shrinking function into a function that shrinks triples.
Turn a shrinking function into a function that shrinks quadruples.
Like shrinkTuple, but for triples
Combine two shrinking functions to shrink a tuple.
upTo generates an integer between 0 (inclusive) and n.
Instances5GGenValid
GGenValid U1Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GGenValid (K1 i a)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GGenValid a, GGenValid b) => GGenValid (a :*: b)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GGenValid a, GGenValid b) => GGenValid (a :+: b)Defined in genvalidity-1.1.1.0 · Data.GenValidityGGenValid a => GGenValid (M1 i c a)Defined in genvalidity-1.1.1.0 · Data.GenValidity
Methods
gValidRecursivelyShrink :: f a -> [f a]
Instances6GValidRecursivelyShrink
GValidRecursivelyShrink U1Defined in genvalidity-1.1.1.0 · Data.GenValidityGValidRecursivelyShrink V1Defined in genvalidity-1.1.1.0 · Data.GenValidityGenValid a => GValidRecursivelyShrink (K1 i a)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GValidRecursivelyShrink f, GValidRecursivelyShrink g) => GValidRecursivelyShrink (f :*: g)Defined in genvalidity-1.1.1.0 · Data.GenValidity(GValidRecursivelyShrink f, GValidRecursivelyShrink g) => GValidRecursivelyShrink (f :+: g)Defined in genvalidity-1.1.1.0 · Data.GenValidityGValidRecursivelyShrink f => GValidRecursivelyShrink (M1 i c f)Defined in genvalidity-1.1.1.0 · Data.GenValidity
Methods
gValidSubterms :: f a -> [a]
Instances6GValidSubterms
GValidSubterms U1 aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubterms V1 aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubterms (K1 i a) bDefined in genvalidity-1.1.1.0 · Data.GenValidity(GValidSubtermsIncl f a, GValidSubtermsIncl g a) => GValidSubterms (f :*: g) aDefined in genvalidity-1.1.1.0 · Data.GenValidity(GValidSubtermsIncl f a, GValidSubtermsIncl g a) => GValidSubterms (f :+: g) aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubterms f a => GValidSubterms (M1 i c f) aDefined in genvalidity-1.1.1.0 · Data.GenValidity
Methods
gValidSubtermsIncl :: f a -> [a]
Instances7GValidSubtermsIncl, …
GValidSubtermsIncl U1 aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubtermsIncl V1 aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubtermsIncl (K1 i a) aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubtermsIncl (K1 i a) bDefined in genvalidity-1.1.1.0 · Data.GenValidity(GValidSubtermsIncl f a, GValidSubtermsIncl g a) => GValidSubtermsIncl (f :*: g) aDefined in genvalidity-1.1.1.0 · Data.GenValidity(GValidSubtermsIncl f a, GValidSubtermsIncl g a) => GValidSubtermsIncl (f :+: g) aDefined in genvalidity-1.1.1.0 · Data.GenValidityGValidSubtermsIncl f a => GValidSubtermsIncl (M1 i c f) aDefined in genvalidity-1.1.1.0 · Data.GenValidity
Shrink a list of values given a shrinking function for individual values.
Generates a random permutation of the given list.
Generate a valid value by generating all the sub parts using the Generic instance, and trying that until a valid value has been generated
genValidStructurally = genValidStructurallyWithoutExtraChecking `suchThat` isValidThis is probably the function that you are looking for. If you do use this function to override genValid, you probably also want to use shrinkValidStructurally to override shrinkValid.
Generate a valid value by generating all the sub parts using the Generic instance,
This generator is _not_ guaranteed to generate a valid value.
This is probably _not_ the function that you are looking for when overriding genValid _unless_ the type in question has no _extra_ validity constraints on top of the validity of its sub parts.
Shrink a term to any of its immediate valid subterms, and also recursively shrink all subterms, and then filtering out the results that are not valid.
shrinkValidStructurally = filter isValid . shrinkValidStructurallyWithoutExtraFilteringThis is probably the function that you are looking for.
Shrink a term to any of its immediate valid subterms, and also recursively shrink all subterms.
This shrinking function is _not_ guaranteed to shrink to valid values.
This is probably _not_ the function that you are looking for when overriding shrinkValid _unless_ the type in question has no _extra_ validity constraints on top of the validity of its sub parts.
All immediate validSubterms of a term.
Declare a sub-part as a necessary part for validation, and annotate it with a name.
Example:
validate (a, b) =
mconcat
[ annotate a "The first element of the tuple"
, annotate b "The second element of the tuple"
]Check that a given invariant holds.
The given string should describe the invariant, not the violation.
Example:
check (x < 5) "x is strictly smaller than 5"instead of
check (x < 5) "x is greater than 5"validate a given value.
This function returns either all the reasons why the given value is invalid, in the form of a list of ValidationChains, or it returns Right with the input value, as evidence that it is valid.
Note: You may want to use prettyValidation instead, if you want to display these ValidationChains to a user.
Construct a valid element from an unchecked element
Construct a valid element from an unchecked element, throwing error on invalid elements.
check, but with the arguments flipped
Decorate a validation with a location
Decorate a piecewise validation of a list with their location in the list
decorateList, but specifically for Strings
decorateString = decorateListannotate, but with the arguments flipped.
Construct a trivially invalid Validation
Example:
data Wrong
= Wrong
| Fine
deriving (Show, Eq)
instance Validity Wrong where
validate w =
case w of
Wrong -> invalid "Wrong"
Fine -> validCheck whether a value is not valid.
isInvalid = not . isValidRender a Validation in a somewhat pretty way.
This function will return Nothing if the Validation concerned a valid value.
Declare any value to be valid in validation
trivialValidation a = seq a memptyCheck if a Validation concerns a valid value.
The result of validating a value.
mempty means the value was valid.
This type intentionally doesn't have a Validity instance to make sure you can never accidentally use annotate or delve twice.
Constructors
Instances6Eq, Show, Generic, Semigroup, Monoid, Rep
Eq ValidationDefined in validity-0.12.1.0 · Data.ValidityShow ValidationDefined in validity-0.12.1.0 · Data.ValidityGeneric ValidationDefined in validity-0.12.1.0 · Data.ValiditySemigroup ValidationDefined in validity-0.12.1.0 · Data.ValidityMonoid ValidationDefined in validity-0.12.1.0 · Data.Validitytype Rep Validation = D1 ('MetaDataDefined in validity-0.12.1.0 · Data.Validity"Validation"
"Data.Validity"
"validity-0.12.1.0-6jTAUZ5lsTi4JKna4jrgxH"
'True) (C1 ('MetaCons"Validation"
'PrefixI 'True) (S1 ('MetaSel ('Just"unValidation"
) 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 [ValidationChain])))
Constructors
Instances5Eq, Show, Generic, Validity, Rep
Eq ValidationChainDefined in validity-0.12.1.0 · Data.ValidityShow ValidationChainDefined in validity-0.12.1.0 · Data.ValidityGeneric ValidationChainDefined in validity-0.12.1.0 · Data.ValidityValidity ValidationChainDefined in validity-0.12.1.0 · Data.Validitytype Rep ValidationChain = D1 ('MetaDataDefined in validity-0.12.1.0 · Data.Validity"ValidationChain"
"Data.Validity"
"validity-0.12.1.0-6jTAUZ5lsTi4JKna4jrgxH"
'False) (C1 ('MetaCons"Violated"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String)) :+: C1 ('MetaCons"Location"
'PrefixI 'False) (S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 String) :*: S1 ('MetaSel 'Nothing 'NoSourceUnpackedness 'NoSourceStrictness 'DecidedLazy) (Rec0 ValidationChain)))