packages feed

validity 0.3.2.0 → 0.3.3.0

raw patch · 2 files changed

+42/−7 lines, 2 filesdep ~base

Dependency ranges changed: base

Files

src/Data/Validity.hs view
@@ -1,8 +1,8 @@+{-# LANGUAGE CPP #-} {-# LANGUAGE FlexibleInstances #-} {-# LANGUAGE TypeOperators #-} {-# LANGUAGE FlexibleContexts #-} {-# LANGUAGE DefaultSignatures #-}-{-# OPTIONS_GHC -Wno-redundant-constraints #-}  {-| @@ -43,14 +43,38 @@  import Data.Fixed (Fixed(MkFixed), HasResolution) import Data.Maybe (Maybe, fromMaybe)+import Data.Word (Word, Word8, Word16) import GHC.Generics+#if MIN_VERSION_base(4,8,0) import GHC.Natural (Natural, isValidNatural)+#endif import GHC.Real (Ratio(..))  -- | A class of types that have additional invariants defined upon them -- that aren't enforced by the type system+--+-- 'isValid' should be an underapproximation of actual validity.+--+-- This means that if 'isValid' is not a perfect representation of actual+-- validity, for safety reasons, it should never return 'True' for invalid+-- values, but it may return 'False' for valid values.+--+-- For example:+--+-- > isValid = const False+--+-- is a valid implementation for any type, because it never returns 'True'+-- for invalid values.+--+-- > isValid (Even i) = i == 2+--+-- is a valid implementation for @newtype Even = Even Int@, but+--+-- > isValid (Even i) = even i || i == 1+--+-- is not because it returns 'True' for an invalid value: '1'. class Validity a where-    isValid :: a -> Bool -- ^ Check whether a given value is a valid value.+    isValid :: a -> Bool     default isValid :: (Generic a, GValidity (Rep a)) =>         a -> Bool     isValid = gIsValid . from@@ -118,6 +142,14 @@ instance Validity Word where     isValid = const True +-- | Trivially valid+instance Validity Word8 where+    isValid = const True++-- | Trivially valid+instance Validity Word16 where+    isValid = const True+ -- | NOT trivially valid: -- -- * NaN is not valid.@@ -142,11 +174,13 @@ -- Even though this is not technically sound, it is good enough for now. instance Validity Integer where     isValid = const True-+#if MIN_VERSION_base(4,8,0) -- | Valid according to 'isValidNatural'+--+-- Only available with @base >= 4.8@. instance Validity Natural where     isValid = isValidNatural-+#endif -- | Valid if the contained 'Integer's are valid and the denominator is -- strictly positive. instance Validity Rational where
validity.cabal view
@@ -1,5 +1,5 @@ name: validity-version: 0.3.2.0+version: 0.3.3.0 cabal-version: >=1.10 build-type: Simple license: MIT@@ -34,7 +34,8 @@         Data.RelativeValidity         Data.Validity     build-depends:-        base >=4.8 && <5+        base >=4.7 && <5     default-language: Haskell2010     hs-source-dirs: src-+    if impl(ghc >= 8.0.0)+        ghc-options: -Wno-redundant-constraints