HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulegenvalidity-sydtest-1.0.0.0Haskell2010

Test.Syd.Validity.Property

  • 2 types
  • 9 classes
  • 181 values
classclass Validity a where
#

A class of types that have additional invariants defined upon them

Methods

Instances79Validity, …
  • Validity KeyDefined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphan
  • Validity ValueDefined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphan

    A Value is valid if the recursive components are valid.

  • Validity UnionDefined in autodocodec-0.5.0.0 · Autodocodec.Codec
  • Validity JSONSchemaDefined in autodocodec-schema-0.2.0.1 · Autodocodec.Schema
  • Validity KeyRequirementDefined in autodocodec-schema-0.2.0.1 · Autodocodec.Schema
  • Validity ObjectSchemaDefined in autodocodec-schema-0.2.0.1 · Autodocodec.Schema
  • Validity ByteStringDefined in validity-bytestring-0.4.1.1 · Data.Validity.ByteString · orphan

    A ByteString is 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 · orphan

    A lazy ByteString is valid according to its chunks.

  • Validity ShortByteStringDefined in validity-bytestring-0.4.1.1 · Data.Validity.ByteString · orphan

    Trivially 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.Validity

    Trivially 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-gmp versus integer-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.Validity

    Valid according to isValidNatural

  • Validity Int16Defined in validity-0.12.1.0 · Data.Validity
  • Validity Int32Defined in validity-0.12.1.0 · Data.Validity
  • Validity Int64Defined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity Int8Defined in validity-0.12.1.0 · Data.Validity
  • Validity Word16Defined in validity-0.12.1.0 · Data.Validity
  • Validity Word32Defined in validity-0.12.1.0 · Data.Validity
  • Validity Word64Defined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity Word8Defined in validity-0.12.1.0 · Data.Validity
  • Validity BoolDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity CharDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity DoubleDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid:

  • Validity FloatDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid:

  • Validity IntDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity OrderingDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity WordDefined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity ArgDefined in opt-env-conf-0.11.0.0 · OptEnvConf.Args
  • Validity ArgsDefined in opt-env-conf-0.11.0.0 · OptEnvConf.Args
  • Validity DashedDefined in opt-env-conf-0.11.0.0 · OptEnvConf.Args
  • Validity EnvMapDefined in opt-env-conf-0.11.0.0 · OptEnvConf.EnvMap
  • Validity ChunkDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Chunk
  • Validity ColourDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Chunk
  • Validity BlinkingDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity CSIDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity ColourIntensityDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity ConsoleIntensityDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity ConsoleLayerDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity SGRDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity TerminalColourDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity UnderliningDefined in safe-coloured-text-0.3.0.2 · Text.Colour.Code
  • Validity TableDefined in safe-coloured-text-layout-0.2.0.1 · Text.Colour.Layout
  • Validity TableBackgroundDefined in safe-coloured-text-layout-0.2.0.1 · Text.Colour.Layout
  • Validity ScientificDefined in validity-scientific-0.2.0.3 · Data.Validity.Scientific · orphan

    A Scientific is valid according to the validity of its coefficient and exponent.

  • Validity TextDefined in validity-text-0.3.1.3 · Data.Validity.Text · orphan

    A text is valid if the internal structure is consistent.

  • Validity TextDefined in validity-text-0.3.1.3 · Data.Validity.Text · orphan

    A lazy text value is valid if all the internal chunks are valid and nonempty

  • Validity ValidationChainDefined in validity-0.12.1.0 · Data.Validity
  • Validity ()Defined in validity-0.12.1.0 · Data.Validity

    Trivially valid

  • Validity a => Validity (Bounds a)Defined in autodocodec-0.5.0.0 · Autodocodec.Codec
  • Validity a => Validity (First a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Last a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Tree a)Defined in validity-containers-0.5.0.5 · Data.Validity.Tree · orphan

    A Tree of things is valid if all the things in the Tree are valid.

  • Validity a => Validity (NonEmpty a)Defined in validity-0.12.1.0 · Data.Validity

    A 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.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (First a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Last a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Dual a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Maybe a)Defined in validity-0.12.1.0 · Data.Validity

    A 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.Args
  • Validity a => Validity (Vector a)Defined in validity-vector-0.2.0.3 · Data.Validity.Vector · orphan

    A Vector of things is valid if all the elements are valid.

    TODO make a more comprehensive instance that looks at implementation and the underlying Array

  • Validity a => Validity [a]Defined in validity-0.12.1.0 · Data.Validity

    A 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 instance

  • Validity v => Validity (KeyMap v)Defined in validity-aeson-0.2.0.5 · Data.Validity.Aeson · orphan
  • Validity v => Validity (IntMap v)Defined in validity-containers-0.5.0.5 · Data.Validity.IntMap · orphan

    A IntMap of things is valid if all the keys and values are valid and the IntMap itself is valid.

  • Validity v => Validity (Seq v)Defined in validity-containers-0.5.0.5 · Data.Validity.Sequence · orphan

    A 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 · orphan

    A HashSet of things is valid if all the elements are valid and the underlying HashMap is 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

    A Set of things is valid if all the elements are valid and the Set itself is valid.

  • (Validity a, Ord a, Num a, Integral a) => Validity (Ratio a)Defined in validity-0.12.1.0 · Data.Validity

    Valid 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 · orphan
  • HasResolution a => Validity (Fixed a)Defined in validity-0.12.1.0 · Data.Validity

    Valid 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

    A Map of things is valid if all the keys and values are valid and the Map itself is valid.

  • (Validity a, Validity b) => Validity (Either a b)Defined in validity-0.12.1.0 · Data.Validity

    Any 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.Validity

    Any 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 · orphan

    A HashMap of things is valid if all the keys and values are valid.

    The 'unordered-containers' package does not export any more functionality concerning a HashMap, so no more accurate validity instance can be made.

  • Validity (f a) => Validity (Alt f a)Defined in validity-0.12.1.0 · Data.Validity

    Valid values the same as it's base type:

  • Validity a => Validity (Const a b)Defined in validity-0.12.1.0 · Data.Validity

    Valid 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.Validity

    Any 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.Validity

    Any 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.Validity

    Any 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.Validity

    Any sextuple of things is valid if all six of its elements are valid

classclass Semigroup a => Monoid a where
#

The class of monoids (types with an associative binary operation that has an identity). Instances should satisfy the following:

Right identity

x <> mempty = x

Left identity

mempty <> x = x

Associativity

x <> (y <> z) = (x <> y) <> z

(

Semigroup

law)

Concatenation

mconcat = foldr (<>) mempty

You can alternatively define mconcat instead of mempty, in which case the laws are:

Unit

mconcat (pure x) = x

Multiplication

mconcat (join xss) = mconcat (fmap mconcat xss)

Subclass

mconcat (toList xs) = sconcat xs

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 :: a

    Identity of mappend

    Examples
    Example1 expression
    "Hello world" <> mempty"Hello world"
    Example1 expression
    mempty <> [1, 2, 3][1,2,3]
  • mappend :: a -> a -> a

    An 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] -> a

    Fold 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.Internal
  • Monoid KeyDefined in aeson-2.2.3.0 · Data.Aeson.Key
  • Monoid MoreDefined in attoparsec-0.14.4 · Data.Attoparsec.Internal.Types
  • Monoid ByteArrayDefined in base-4.20.2.0 · Data.Array.Byte
  • Monoid PokeDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.Write
  • Monoid WriteDefined in blaze-builder-0.4.4.1 · Blaze.ByteString.Builder.Internal.Write
  • Monoid BuilderDefined in bytestring-0.12.2.0 · Data.ByteString.Builder.Internal
  • Monoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Internal.Type
  • Monoid ByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Lazy.Internal
  • Monoid ShortByteStringDefined in bytestring-0.12.2.0 · Data.ByteString.Short.Internal
  • Monoid IntSetDefined in containers-0.7 · Data.IntSet.Internal
  • Monoid AllDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid AnyDefined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid EventDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Monoid EventLifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types
  • Monoid LifetimeDefined in ghc-internal-9.1003.0 · GHC.Internal.Event.Internal.Types

    mappend takes the longer of two lifetimes.

  • Monoid ExceptionContextDefined in ghc-internal-9.1003.0 · GHC.Internal.Exception.Context
  • Monoid OrderingDefined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid 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.Types
  • Monoid WindowsStringDefined in os-string-2.0.7 · System.OsString.Internal.Types
  • Monoid DocDefined in pretty-1.1.3.6 · Text.PrettyPrint.HughesPJ
  • Monoid ElementDefined in svg-builder-0.1.1 · Graphics.Svg.Core
  • Monoid TestSuiteStatsDefined in sydtest-0.22.0.0 · Test.Syd.SpecDef
  • Monoid TermOutputDefined in terminfo-0.4.1.7 · System.Console.Terminfo.Base
  • Monoid TextDefined in text-2.1.3 · Data.Text · orphan
  • Monoid BuilderDefined in text-2.1.3 · Data.Text.Internal.Builder
  • Monoid TextDefined in text-2.1.3 · Data.Text.Lazy · orphan
  • Monoid StrictTextBuilderDefined in text-2.1.3 · Data.Text.Internal.StrictBuilder
  • Monoid ShortTextDefined in text-short-0.1.6 · Data.Text.Short.Internal
  • Monoid CalendarDiffDaysDefined in time-1.12.2 · Data.Time.Calendar.CalendarDiffDays

    Additive

  • Monoid CalendarDiffTimeDefined in time-1.12.2 · Data.Time.LocalTime.Internal.CalendarDiffTime

    Additive

  • Monoid StatxFlagsDefined in unix-2.8.7.0 · System.Posix.Files.Common
  • Monoid StatxMaskDefined in unix-2.8.7.0 · System.Posix.Files.Common
  • Monoid ValidationDefined in validity-0.12.1.0 · Data.Validity
  • Monoid ()Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid (KeyMap v)Defined in aeson-2.2.3.0 · Data.Aeson.KeyMap
  • Monoid (IResult a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.Internal
  • Monoid (Parser a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.Internal
  • Monoid (Result a)Defined in aeson-2.2.3.0 · Data.Aeson.Types.Internal
  • Monoid (Comparison a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on comparisons always returns EQ. Without newtypes this equals pure (pure EQ).

    mempty :: Comparison a
    mempty = Comparison _ _ -> EQ
    
  • Monoid (Equivalence a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on equivalences always returns True. Without newtypes this equals pure (pure True).

    mempty :: Equivalence a
    mempty = Equivalence _ _ -> True
    
  • Monoid (Predicate a)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty on predicates always returns True. Without newtypes this equals pure True.

    mempty :: Predicate a
    mempty = _ -> True
    
  • Monoid (PutM ())Defined in binary-0.8.9.3 · Data.Binary.Put
  • Monoid (IntMap a)Defined in containers-0.7 · Data.IntMap.Internal
  • Monoid (Seq a)Defined in containers-0.7 · Data.Sequence.Internal
  • Monoid (MergeSet a)Defined in containers-0.7 · Data.Set.Internal
  • Monoid (DList a)Defined in dlist-1.0 · Data.DList.Internal
  • Monoid (First a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monoid (Last a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Monoid
  • Monoid (Endo a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid (Builder f)Defined in opt-env-conf-0.11.0.0 · OptEnvConf.Setting
  • Monoid (Doc a)Defined in pretty-1.1.3.6 · Text.PrettyPrint.Annotated.HughesPJ
  • Monoid (Array a)Defined in primitive-0.9.1.0 · Data.Primitive.Array
  • Monoid (PrimArray a)Defined in primitive-0.9.1.0 · Data.Primitive.PrimArray
  • Monoid (SmallArray a)Defined in primitive-0.9.1.0 · Data.Primitive.SmallArray
  • Monoid (Validity k)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal.Debug
  • Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector
  • Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Strict
  • Monoid (YamlParser a)Defined in yaml-0.11.11.2 · Data.Yaml.Parser
  • Monoid [a]Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid a => Monoid (STM a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Conc.Sync
  • Monoid a => Monoid (Identity a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Identity
  • Monoid a => Monoid (Down a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Ord
  • Monoid a => Monoid (Dual a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Monoid a => Monoid (IO a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid a => Monoid (Q a)Defined in template-haskell-2.22.0.0 · Language.Haskell.TH.Syntax
  • Monoid a => Monoid (a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Monoid m => Monoid (WrappedMonoid m)Defined in base-4.20.2.0 · Data.Semigroup
  • Monoid p => Monoid (Par1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Semigroup a => Monoid (Maybe a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base

    Lift a semigroup into Maybe forming a Monoid according to http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be turned into a monoid simply by adjoining an element e not in S and defining e*e = e and e*s = s = s*e for all s ∈ S."

    Since 4.11.0: constraint on inner a value generalised from Monoid to Semigroup.

  • Semigroup a => Monoid (Maybe a)Defined in strict-0.5.1 · Data.Strict.Maybe
  • Bits a => Monoid (Ior a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • Bits a => Monoid (Xor a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits
  • FiniteBits a => Monoid (And a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Bits

    This 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.Bits

    This 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.Storable
  • Num a => Monoid (Product a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Num a => Monoid (Sum a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Ord a => Monoid (Set a)Defined in containers-0.7 · Data.Set.Internal
  • Ord a => Monoid (Max a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Ord a => Monoid (Min a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Utils
  • Hashable a => Monoid (HashSet a)Defined in unordered-containers-0.2.21 · Data.HashSet.Internal

    mempty = empty

    mappend = union

    O(n+m)

    To obtain good performance, the smaller set must be presented as the first argument.

    Examples
    Example1 expression
    mappend (fromList [1,2]) (fromList [2,3])fromList [1,2,3]
  • Prim a => Monoid (Vector a)Defined in vector-0.13.2.0 · Data.Vector.Primitive
  • Unbox 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.Semigroup
  • Monad m => Monoid (ZeptoT m a)Defined in attoparsec-0.14.4 · Data.Attoparsec.Zepto
  • Monoid (Parser i a)Defined in attoparsec-0.14.4 · Data.Attoparsec.Internal.Types
  • Monoid (Proxy s)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Proxy
  • Monoid (U1 p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid a => Monoid (Op a b)Defined in base-4.20.2.0 · Data.Functor.Contravariant

    mempty @(Op a b) without newtypes is mempty @(b->a) = _ -> mempty.

    mempty :: Op a b
    mempty = Op _ -> mempty
    
  • Monoid a => Monoid (ST s a)Defined in ghc-internal-9.1003.0 · GHC.Internal.ST
  • Monoid b => Monoid (a -> b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Base
  • Ord k => Monoid (Map k v)Defined in containers-0.7 · Data.Map.Internal
  • Hashable k => Monoid (HashMap k v)Defined in unordered-containers-0.2.21 · Data.HashMap.Internal

    mempty = empty

    mappend = union

    If a key occurs in both maps, the mapping from the first will be the mapping in the result.

    Examples
    Example1 expression
    mappend (fromList [(1,'a'),(2,'b')]) (fromList [(2,'c'),(3,'d')])fromList [(1,'a'),(2,'b'),(3,'d')]
  • (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.Zip
  • Alternative f => Monoid (Alt f a)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Semigroup.Internal
  • Applicative f => Monoid (Traversed a f)Defined in indexed-traversable-0.1.4 · WithIndex
  • Monad m => Monoid (Sequenced a m)Defined in indexed-traversable-0.1.4 · WithIndex
  • Monoid (f p) => Monoid (Rec1 f p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid a => Monoid (Const a b)Defined in ghc-internal-9.1003.0 · GHC.Internal.Data.Functor.Const
  • Monoid 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.Tagged
  • Monad m => Monoid (ConduitT i o m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.Conduit
  • Monoid 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.Prim

    The Monoid instance for ParsecT is used for the same purposes as the Semigroup instance.

  • Monoid (f (g a)) => Monoid (Compose f g a)Defined in base-4.20.2.0 · Data.Functor.Compose
  • Monoid (f (g p)) => Monoid ((:.:) f g p)Defined in ghc-internal-9.1003.0 · GHC.Internal.Generics
  • Monoid (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.Base
  • Monad m => Monoid (Pipe l i o u m ())Defined in conduit-1.3.6.1 · Data.Conduit.Internal.Pipe
classclass Validity a => GenValid a where
#

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 = shrinkValid

Methods

  • genValid :: Gen a

    Generate a valid datum, this should cover all possible valid values in the type

    The default implementation is as follows:

     genValid = genValidStructurally

    To 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 = shrinkValidStructurally

    It 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, …
valueprettyValidate :: Validity a => a -> Either String a
#

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.

classclass Semigroup a where
#

The class of semigroups (types with an associative binary operation).

Instances should satisfy the following:

Associativity

x <> (y <> z) = (x <> y) <> z

You can alternatively define sconcat instead of (<>), in which case the laws are:

Unit

sconcat (pure x) = x

Multiplication

sconcat (join xss) = sconcat (fmap sconcat xss)

Methods

  • (<>) :: a -> a -> ainfixr 6

    An 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 -> a

    Reduce 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 -> a

    Repeat a value n times.

    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 use stimesMonoid.

    By making this a member of the class, idempotent semigroups and monoids can upgrade this to execute in \mathcal{O}(1) by picking stimes = stimesIdempotent or stimes = stimesIdempotentMonoid respectively.

    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, …
valuearbPartition :: Int -> Gen [Int]
#

'arbPartition n' generates a list ls such that 'sum ls' equals n, approximately.

valuegenFloatX :: (Read a, RealFloat a, Bounded w, Random w) => (w -> a) -> Gen a
#

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.

valuegenIntX :: (Integral a, Bounded a, Random a) => Gen a
#

Generate Int, Int8, Int16, Int32 and Int64 values smartly.

  • Some at the border

  • Some around zero

  • Mostly uniformly

valuegenListOf :: Gen a -> Gen [a]
#

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.

valuegenSplit :: Int -> Gen (Int, Int)
#

'genSplit a' generates a tuple '(b, c)' such that 'b + c' equals a.

valuegenSplit3 :: Int -> Gen (Int, Int, Int)
#

'genSplit3 a' generates a triple '(b, c, d)' such that 'b + c + d' equals a.

valuegenSplit4 :: Int -> Gen (Int, Int, Int, Int)
#

'genSplit4 a' generates a quadruple '(b, c, d, e)' such that 'b + c + d + e' equals a.

valuegenWordX :: (Integral a, Bounded a, Random a) => Gen a
#

Generate Word, Word8, Word16, Word32 and Word64 values smartly.

  • Some at the border

  • Some around zero

  • Mostly uniformly

valueshrinkQuadruple
  1. :: a -> [a]
  2. -> b -> [b]
  3. -> c -> [c]
  4. -> d -> [d]
  5. -> (a, b, c, d)
  6. -> [(a, b, c, d)]
#

Like shrinkTuple, but for quadruples

valueshrinkT2 :: (a -> [a]) -> (a, a) -> [(a, a)]
#

Turn a shrinking function into a function that shrinks tuples.

valueshrinkT3 :: (a -> [a]) -> (a, a, a) -> [(a, a, a)]
#

Turn a shrinking function into a function that shrinks triples.

valueshrinkT4 :: (a -> [a]) -> (a, a, a, a) -> [(a, a, a, a)]
#

Turn a shrinking function into a function that shrinks quadruples.

valueshrinkTuple :: (a -> [a]) -> (b -> [b]) -> (a, b) -> [(a, b)]
#

Combine two shrinking functions to shrink a tuple.

classclass GGenValid (f :: Type -> Type) where
#

Methods

Instances5GGenValid
classclass GValidRecursivelyShrink (f :: Type -> Type) where
#

Methods

Instances6GValidRecursivelyShrink
classclass GValidSubterms (f :: Type -> Type) a where
#

Methods

Instances6GValidSubterms
classclass GValidSubtermsIncl (f :: Type -> Type) a where
#

Methods

Instances7GValidSubtermsIncl, …
valueshrinkList :: (a -> [a]) -> [a] -> [[a]]
#

Shrink a list of values given a shrinking function for individual values.

valueshuffle :: [a] -> Gen [a]
#

Generates a random permutation of the given list.

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 . shrinkValidStructurallyWithoutExtraFiltering

This is probably the function that you are looking for.

valueannotate :: Validity a => a -> String -> Validation
#

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"
        ]
valuecheck :: Bool -> String -> Validation
#

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"
valueinvalid :: String -> Validation
#

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 -> valid
newtypenewtype Validation
#

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.

Instances6Eq, Show, Generic, Semigroup, Monoid, Rep
datadata ValidationChain
#
Instances5Eq, Show, Generic, Validity, Rep

Tests for GenValidity instances

1 declaration

Standard tests involving functions

0 declarations

Standard tests involving validity

Standard tests involving functions that can fail

Standard tests involving equivalence of functions

Simple functions

One argument

Two arguments

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

Properties involving idempotence

valueidempotentOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a) -> Property
#

id is idempotent for any type:

Property
idempotentOnArbitrary (id :: Int -> Int)

const, given any input, is idempotent for any type as well:

Property
\int -> idempotentOnArbitrary (const int :: Int -> Int)

Properties of relations

0 declarations

Reflexivity

valuereflexiveOnElem
  1. :: (a -> a -> Bool)

    A relation

  2. -> a

    An element

  3. -> Bool
#

Reflexive(\prec) \quad\equiv\quad \forall a: (a \prec a)

valuereflexivity :: (Show a, GenValid a) => (a -> a -> Bool) -> Property
#
Property
reflexivity ((<=) :: Int -> Int -> Bool)
Property
reflexivity ((==) :: Int -> Int -> Bool)
Property
reflexivity ((>=) :: Int -> Int -> Bool)
Property
reflexivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
reflexivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
reflexivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)
valuereflexivityOnArbitrary
  1. :: (Show a, Arbitrary a)
  2. => a -> a -> Bool
  3. -> Property
#
Property
reflexivityOnArbitrary ((<=) :: Int -> Int -> Bool)
Property
reflexivityOnArbitrary ((==) :: Int -> Int -> Bool)
Property
reflexivityOnArbitrary ((>=) :: Int -> Int -> Bool)
Property
reflexivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
reflexivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
reflexivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)

Transitivity

valuetransitiveOnElems
  1. :: (a -> a -> Bool)

    A relation

  2. -> a
  3. -> a
  4. -> a

    Three elements

  5. -> Bool
#

Transitive(\prec) \quad\equiv\quad \forall a, b, c: ((a \prec b) \wedge (b \prec c)) \Rightarrow (a \prec c)

valuetransitivity :: (Show a, GenValid a) => (a -> a -> Bool) -> Property
#
Property
transitivity ((>) :: Int -> Int -> Bool)
Property
transitivity ((>=) :: Int -> Int -> Bool)
Property
transitivity ((==) :: Int -> Int -> Bool)
Property
transitivity ((<=) :: Int -> Int -> Bool)
Property
transitivity ((<) :: Int -> Int -> Bool)
Property
transitivity (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
transitivity (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
transitivity (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)
valuetransitivityOnArbitrary
  1. :: (Show a, Arbitrary a)
  2. => a -> a -> Bool
  3. -> Property
#
Property
transitivityOnArbitrary ((>) :: Int -> Int -> Bool)
Property
transitivityOnArbitrary ((>=) :: Int -> Int -> Bool)
Property
transitivityOnArbitrary ((==) :: Int -> Int -> Bool)
Property
transitivityOnArbitrary ((<=) :: Int -> Int -> Bool)
Property
transitivityOnArbitrary ((<) :: Int -> Int -> Bool)
Property
transitivityOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
transitivityOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
transitivityOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)

Antisymmetry

valueantisymmetricOnElemsWithEquality
  1. :: (a -> a -> Bool)

    A relation

  2. -> (a -> a -> Bool)

    An equivalence relation

  3. -> a
  4. -> a

    Two elements

  5. -> Bool
#

Antisymmetric(\prec, \doteq) \quad\equiv\quad \forall a, b: ((a \prec b) \wedge (b \prec a)) \Rightarrow (a \doteq b)

valueantisymmetry :: (Show a, Eq a, GenValid a) => (a -> a -> Bool) -> Property
#
Property
antisymmetry ((>) :: Int -> Int -> Bool)
Property
antisymmetry ((>=) :: Int -> Int -> Bool)
Property
antisymmetry ((<=) :: Int -> Int -> Bool)
Property
antisymmetry ((<) :: Int -> Int -> Bool)
Property
antisymmetry (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetry (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetry (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetry ((\x y -> even x && odd y) :: Int -> Int -> Bool)
valueantisymmetryOnArbitrary
  1. :: (Show a, Eq a, Arbitrary a)
  2. => a -> a -> Bool
  3. -> Property
#
Property
antisymmetryOnArbitrary ((>) :: Int -> Int -> Bool)
Property
antisymmetryOnArbitrary ((>=) :: Int -> Int -> Bool)
Property
antisymmetryOnArbitrary ((<=) :: Int -> Int -> Bool)
Property
antisymmetryOnArbitrary ((<) :: Int -> Int -> Bool)
Property
antisymmetryOnArbitrary (Data.List.isPrefixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetryOnArbitrary (Data.List.isSuffixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetryOnArbitrary (Data.List.isInfixOf :: [Int] -> [Int] -> Bool)
Property
antisymmetryOnArbitrary ((\x y -> even x && odd y) :: Int -> Int -> Bool)

Antireflexivity

valueantireflexiveOnElem
  1. :: (a -> a -> Bool)

    A relation

  2. -> a

    An element

  3. -> Bool
#

Antireflexive(\prec) \quad\equiv\quad \forall a: \neg (a \prec a)

valueantireflexivity :: (Show a, GenValid a) => (a -> a -> Bool) -> Property
#
Property
antireflexivity ((<) :: Int -> Int -> Bool)
Property
antireflexivity ((/=) :: Int -> Int -> Bool)
Property
antireflexivity ((>) :: Int -> Int -> Bool)
valueantireflexivityOnArbitrary
  1. :: (Show a, Arbitrary a)
  2. => a -> a -> Bool
  3. -> Property
#
Property
antireflexivityOnArbitrary ((<) :: Int -> Int -> Bool)
Property
antireflexivityOnArbitrary ((/=) :: Int -> Int -> Bool)
Property
antireflexivityOnArbitrary ((>) :: Int -> Int -> Bool)

Symmetry

valuesymmetricOnElems
  1. :: (a -> a -> Bool)

    A relation

  2. -> a
  3. -> a

    Two elements

  4. -> Bool
#

Symmetric(\prec) \quad\equiv\quad \forall a, b: (a \prec b) \Leftrightarrow (b \prec a)

valuesymmetry :: (Show a, GenValid a) => (a -> a -> Bool) -> Property
#
Property
symmetry ((==) :: Int -> Int -> Bool)
Property
symmetry ((/=) :: Int -> Int -> Bool)

Properties of operations

0 declarations

Identity element

Left Identity

valueleftIdentityOnElemWithEquality
  1. :: (b -> a -> a)

    A binary operation

  2. -> (a -> a -> Bool)

    An equality

  3. -> b

    A candidate left-identity

  4. -> a

    An element

  5. -> Bool
#

LeftIdentity(\star, \doteq, b) \quad\equiv\quad \forall a: (b \star a) \doteq a

Right Identity

valuerightIdentityOnElemWithEquality
  1. :: (a -> b -> a)

    A binary operation

  2. -> (a -> a -> Bool)

    An equality

  3. -> b

    A candidate right-identity

  4. -> a

    An element

  5. -> Bool
#

RightIdentity(\star, \doteq, b) \quad\equiv\quad \forall a: (a \star b) \doteq a

Identity

valueidentityOnGen
  1. :: (Show a, Eq a)
  2. => a -> a -> a
  3. -> a
  4. -> Gen a
  5. -> a -> [a]
  6. -> Property
#

Identity(\star, \doteq, b) \quad\equiv\quad LeftIdentity(\star, \doteq, b) \wedge RightIdentity(\star, \doteq, b)

valueidentity :: (Show a, Eq a, GenValid a) => (a -> a -> a) -> a -> Property
#
Property
identity ((*) :: Int -> Int -> Int) 1
Property
identity ((+) :: Int -> Int -> Int) 0

Associativity

valueassociativeOnGens
  1. :: (Show a, Eq a)
  2. => a -> a -> a
  3. -> Gen (a, a, a)
  4. -> (a, a, a) -> [(a, a, a)]
  5. -> Property
#

Associative(\star) \quad\equiv\quad \forall a, b, c: (a \star b) \star c = a \star (b \star c)

valueassociative :: (Show a, Eq a, GenValid a) => (a -> a -> a) -> Property
#
Property
associative ((*) :: Int -> Int -> Int)
Property
associative ((+) :: Int -> Int -> Int)

Commutativity

valuecommutativeOnArbitrary
  1. :: (Show a, Show b, Eq b, Arbitrary a)
  2. => a -> a -> b
  3. -> Property
#
Property
commutativeOnArbitrary ((+) :: Int -> Int -> Int)
Property
commutativeOnArbitrary ((*) :: Int -> Int -> Int)

commutativeOnArbitrary :: (Show a, Eq a, Arbitrary a) => (a -> a -> a) -> Property