-- Hoogle documentation, generated by Haddock
-- See Hoogle, http://www.haskell.org/hoogle/

-- | Validity typeclass
--   
--   For more info, see the readme.
--   
--   Note: There are companion instance packages for this library:
--   
--   
--   
- validity-aeson
--   
- validity-bytestring
--   
- validity-containers
--   
- validity-path
--   
- validity-scientific
--   
- validity-text
--   
- validity-time
--   
- validity-unordered-containers
--   
- validity-uuid
--   
- validity-vector
--   
@package validity
@version 0.12.1.0

-- | Validity is used to specify additional invariants upon values
--   that are not enforced by the type system.
--   
--   Let's take an example. Suppose we were to implement a type
--   Prime that represents prime integers.
--   
--   If you were to completely enforce the invariant that the represented
--   number is a prime, then we could use Natural and only store the
--   index of the given prime in the infinite sequence of prime numbers.
--   This is very safe but also very expensive if we ever want to use the
--   number, because we would have to calculcate all the prime numbers
--   until that index.
--   
--   Instead we choose to implement Prime by a newtype Prime =
--   Prime Int. Now we have to maintain the invariant that the
--   Int that we use to represent the prime is in fact positive
--   and a prime.
--   
--   The Validity typeclass allows us to specify this invariant
--   (and enables testing via the genvalidity libraries:
--   https://hackage.haskell.org/package/genvalidity ):
--   
--   
--   instance Validity Prime where
--       validate (Prime n) = check (isPrime n) "The 'Int' is prime."
--   
--   
--   If certain typeclass invariants exist, you can make these explicit in
--   the validity instance as well. For example, 'Fixed a' is only valid if
--   a has an HasResolution instance, so the correct
--   validity instance is HasResolution a => Validity (Fixed
--   a).
module Data.Validity

-- | A class of types that have additional invariants defined upon them
class Validity a
validate :: Validity a => a -> Validation
($dmvalidate) :: (Validity a, Generic a, GValidity (Rep a)) => a -> Validation

-- | Declare any value to be valid in validation
--   
--   
--   trivialValidation a = seq a mempty
--   
trivialValidation :: a -> Validation
genericValidate :: (Generic a, GValidity (Rep a)) => a -> 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"
--   
check :: Bool -> String -> Validation

-- | check, but with the arguments flipped
declare :: String -> Bool -> 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"
--           ]
--   
annotate :: Validity a => a -> String -> Validation

-- | annotate, but with the arguments flipped.
delve :: Validity a => String -> a -> Validation

-- | Decorate a validation with a location
decorate :: String -> Validation -> Validation

-- | Decorate a piecewise validation of a list with their location in the
--   list
decorateList :: [a] -> (a -> Validation) -> Validation

-- | decorateList, but specifically for Strings
--   
--   
--   decorateString = decorateList
--   
decorateString :: String -> (Char -> Validation) -> 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
--   
invalid :: String -> Validation
valid :: Validation
validateCharNotUtf16SurrogateCodePoint :: Char -> Validation
isUtf16SurrogateCodePoint :: Char -> Bool
validateCharNotLineSeparator :: Char -> Validation
isLineSeparator :: Char -> Bool
validateStringSingleLine :: String -> Validation
isSingleLine :: String -> Bool
validateNotNaN :: RealFloat a => a -> Validation
validateNotInfinite :: RealFloat a => a -> Validation
validateRatioNotNaN :: Integral a => Ratio a -> Validation
validateRatioNotInfinite :: Integral a => Ratio a -> Validation
validateRatioNormalised :: Integral a => Ratio a -> Validation

-- | Check whether a value is valid.
isValid :: Validity a => a -> Bool

-- | Check whether a value is not valid.
--   
--   
--   isInvalid = not . isValid
--   
isInvalid :: Validity a => a -> Bool

-- | Construct a valid element from an unchecked element
constructValid :: Validity a => a -> Maybe a

-- | Construct a valid element from an unchecked element, throwing
--   error on invalid elements.
constructValidUnsafe :: (Show a, Validity a) => a -> a

-- | 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.
newtype Validation
Validation :: [ValidationChain] -> Validation
[unValidation] :: Validation -> [ValidationChain]
data ValidationChain
Violated :: String -> ValidationChain
Location :: String -> ValidationChain -> ValidationChain

-- | 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.
checkValidity :: Validity a => a -> Either [ValidationChain] a

-- | Check if a Validation concerns a valid value.
validationIsValid :: Validation -> Bool

-- | 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.
prettyValidate :: Validity a => a -> Either String a

-- | Render a Validation in a somewhat pretty way.
--   
--   This function will return Nothing if the Validation
--   concerned a valid value.
prettyValidation :: Validation -> Maybe String

-- | 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.
--   Sum and Product.
--   
--   NOTE: Semigroup is a superclass of Monoid since
--   base-4.11.0.0.
class Semigroup a => Monoid a

-- | Identity of mappend
--   
--   
Examples
--   
--   
--   >>> "Hello world" <> mempty
--   "Hello world"
--   
--   
--   
--   >>> mempty <> [1, 2, 3]
--   [1,2,3]
--   
mempty :: Monoid 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.
mappend :: Monoid a => a -> 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.
--   
--   
--   >>> mconcat ["Hello", " ", "Haskell", "!"]
--   "Hello Haskell!"
--   
mconcat :: Monoid a => [a] -> a

-- | 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)
--   
class Semigroup a

-- | An associative operation.
--   
--   
Examples
--   
--   
--   >>> [1,2,3] <> [4,5,6]
--   [1,2,3,4,5,6]
--   
--   
--   
--   >>> Just [1, 2, 3] <> Just [4, 5, 6]
--   Just [1,2,3,4,5,6]
--   
--   
--   
--   >>> putStr "Hello, " <> putStrLn "World!"
--   Hello, World!
--   
(<>) :: Semigroup a => a -> 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:
--   
--   
--   >>> import Data.List.NonEmpty (NonEmpty (..))
--   
--   
--   
--   >>> sconcat $ "Hello" :| [" ", "Haskell", "!"]
--   "Hello Haskell!"
--   
--   
--   
--   >>> sconcat $ Just [1, 2, 3] :| [Nothing, Just [4, 5, 6]]
--   Just [1,2,3,4,5,6]
--   
--   
--   
--   >>> sconcat $ Left 1 :| [Right 2, Left 3, Right 4]
--   Right 2
--   
sconcat :: Semigroup a => NonEmpty 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 <math> by picking
--   stimes = stimesIdempotent or stimes =
--   stimesIdempotentMonoid respectively.
--   
--   
Examples
--   
--   
--   >>> stimes 4 [1]
--   [1,1,1,1]
--   
--   
--   
--   >>> stimes 5 (putStr "hi!")
--   hi!hi!hi!hi!hi!
--   
--   
--   
--   >>> stimes 3 (Right ":)")
--   Right ":)"
--   
stimes :: (Semigroup a, Integral b) => b -> a -> a
infixr 6 <>
instance GHC.Classes.Eq Data.Validity.Validation
instance GHC.Classes.Eq Data.Validity.ValidationChain
instance (Data.Validity.GValidity a, Data.Validity.GValidity b) => Data.Validity.GValidity (a GHC.Internal.Generics.:*: b)
instance (Data.Validity.GValidity a, Data.Validity.GValidity b) => Data.Validity.GValidity (a GHC.Internal.Generics.:+: b)
instance Data.Validity.Validity a => Data.Validity.GValidity (GHC.Internal.Generics.K1 GHC.Internal.Generics.R a)
instance (Data.Validity.GValidity a, GHC.Internal.Generics.Datatype c) => Data.Validity.GValidity (GHC.Internal.Generics.M1 GHC.Internal.Generics.D c a)
instance (Data.Validity.GValidity a, GHC.Internal.Generics.Constructor c) => Data.Validity.GValidity (GHC.Internal.Generics.M1 GHC.Internal.Generics.C c a)
instance (Data.Validity.GValidity a, GHC.Internal.Generics.Selector c) => Data.Validity.GValidity (GHC.Internal.Generics.M1 GHC.Internal.Generics.S c a)
instance Data.Validity.GValidity GHC.Internal.Generics.U1
instance Data.Validity.GValidity GHC.Internal.Generics.V1
instance GHC.Internal.Generics.Generic Data.Validity.Validation
instance GHC.Internal.Generics.Generic Data.Validity.ValidationChain
instance GHC.Internal.Base.Monoid Data.Validity.Validation
instance GHC.Internal.Base.Semigroup Data.Validity.Validation
instance GHC.Internal.Show.Show Data.Validity.Validation
instance GHC.Internal.Show.Show Data.Validity.ValidationChain
instance Data.Validity.Validity (f a) => Data.Validity.Validity (GHC.Internal.Data.Semigroup.Internal.Alt f a)
instance Data.Validity.Validity GHC.Types.Bool
instance Data.Validity.Validity GHC.Types.Char
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Data.Functor.Const.Const a b)
instance Data.Validity.Validity GHC.Types.Double
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Data.Semigroup.Internal.Dual a)
instance (Data.Validity.Validity a, Data.Validity.Validity b) => Data.Validity.Validity (GHC.Internal.Data.Either.Either a b)
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Data.Monoid.First a)
instance Data.Validity.Validity a => Data.Validity.Validity (Data.Semigroup.First a)
instance Data.Fixed.HasResolution a => Data.Validity.Validity (Data.Fixed.Fixed a)
instance Data.Validity.Validity GHC.Types.Float
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Data.Functor.Identity.Identity a)
instance Data.Validity.Validity GHC.Types.Int
instance Data.Validity.Validity GHC.Internal.Int.Int16
instance Data.Validity.Validity GHC.Internal.Int.Int32
instance Data.Validity.Validity GHC.Internal.Int.Int64
instance Data.Validity.Validity GHC.Internal.Int.Int8
instance Data.Validity.Validity GHC.Num.Integer.Integer
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Data.Monoid.Last a)
instance Data.Validity.Validity a => Data.Validity.Validity (Data.Semigroup.Last a)
instance Data.Validity.Validity a => Data.Validity.Validity [a]
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Maybe.Maybe a)
instance Data.Validity.Validity GHC.Num.Natural.Natural
instance Data.Validity.Validity a => Data.Validity.Validity (GHC.Internal.Base.NonEmpty a)
instance Data.Validity.Validity GHC.Types.Ordering
instance (Data.Validity.Validity a, GHC.Classes.Ord a, GHC.Internal.Num.Num a, GHC.Internal.Real.Integral a) => Data.Validity.Validity (GHC.Internal.Real.Ratio a)
instance (Data.Validity.Validity a, Data.Validity.Validity b) => Data.Validity.Validity (a, b)
instance (Data.Validity.Validity a, Data.Validity.Validity b, Data.Validity.Validity c) => Data.Validity.Validity (a, b, c)
instance (Data.Validity.Validity a, Data.Validity.Validity b, Data.Validity.Validity c, Data.Validity.Validity d) => Data.Validity.Validity (a, b, c, d)
instance (Data.Validity.Validity a, Data.Validity.Validity b, Data.Validity.Validity c, Data.Validity.Validity d, Data.Validity.Validity e) => Data.Validity.Validity (a, b, c, d, e)
instance (Data.Validity.Validity a, Data.Validity.Validity b, Data.Validity.Validity c, Data.Validity.Validity d, Data.Validity.Validity e, Data.Validity.Validity f) => Data.Validity.Validity (a, b, c, d, e, f)
instance Data.Validity.Validity ()
instance Data.Validity.Validity Data.Validity.ValidationChain
instance Data.Validity.Validity GHC.Types.Word
instance Data.Validity.Validity GHC.Internal.Word.Word16
instance Data.Validity.Validity GHC.Internal.Word.Word32
instance Data.Validity.Validity GHC.Internal.Word.Word64
instance Data.Validity.Validity GHC.Internal.Word.Word8
