-- Hoogle documentation, generated by Haddock -- See Hoogle, http://www.haskell.org/hoogle/ -- | Validity typeclass -- -- Please see README.md @package validity @version 0.2.0.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 Numeric.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 -- isValid (Prime n) = isPrime n --module Data.Validity -- | A class of types that have additional invariants defined upon them -- that aren't enforced by the type system class Validity a isValid :: Validity a => a -> Bool instance (Data.Validity.Validity a, Data.Foldable.Foldable t) => Data.Validity.Validity (t a) -- | Relative validity module Data.RelativeValidity -- | A class of types that have additional invariants defined upon them -- that aren't enforced by the type system -- -- If there is a Validity a instance as well, then a -- isValidFor b should imply isValid a for any -- b. -- -- If there is a Validity b instance as well, then a -- isValidFor b should imply isValid b for any -- a. class RelativeValidity a b isValidFor :: RelativeValidity a b => a -> b -> Bool