validation 0.4.3 → 0.5.0
raw patch · 4 files changed
+179/−123 lines, 4 filesdep +mtldep ~basedep ~lensdep ~transformers
Dependencies added: mtl
Dependency ranges changed: base, lens, transformers
Files
- LICENSE +1/−1
- changelog +9/−0
- src/Data/Validation.hs +111/−110
- validation.cabal +58/−12
LICENSE view
@@ -1,5 +1,5 @@ Copyright 2010-2013 Tony Morris, Nick Partridge-Copyright 2014 NICTA Limited+Copyright 2014,2015 NICTA Limited All rights reserved.
changelog view
@@ -1,3 +1,12 @@+0.5.0++* Export the `ValidationB` (formerly `ValidationTB`) data type.+* Renamed `ValidationTB` to `ValidationB`.+* Add upper-bounds on some dependencies.+* Move repository to https://github.com/NICTA/validation.+* Add README.+* Update copyright notice for 2015.+ 0.4.3 * Rename `ValidationT` to `ValidationTB`
src/Data/Validation.hs view
@@ -9,6 +9,7 @@ AccValidation(..) , Validation(..) , ValidationT(..)+, ValidationB(..) , Validation' -- * Prisms , _Failure@@ -54,7 +55,7 @@ -- >>> instance (Arbitrary err, Arbitrary a) => Arbitrary (AccValidation err a) where arbitrary = fmap (either (_Failure #) (_Success #)) arbitrary -- >>> instance (Arbitrary err, Arbitrary a) => Arbitrary (Validation err a) where arbitrary = fmap (either (_Failure #) (_Success #)) arbitrary -- >>> instance (Applicative m, Arbitrary err, Arbitrary a) => Arbitrary (ValidationT err m a) where arbitrary = fmap (ValidationT . pure) arbitrary--- >>> instance (Applicative m, Arbitrary err, Arbitrary a) => Arbitrary (ValidationTB m err a) where arbitrary = fmap (ValidationTB . pure) arbitrary+-- >>> instance (Applicative m, Arbitrary err, Arbitrary a) => Arbitrary (ValidationB m err a) where arbitrary = fmap (ValidationB . pure) arbitrary -- | A value of the type @err@ or @a@, however, the @Applicative@ instance -- accumulates values. This is witnessed by the @Semigroup@ context on the instance.@@ -570,172 +571,172 @@ {-# INLINE liftValidationT #-} -- | The bifunctor version of ValidationT-data ValidationTB m err a =- ValidationTB {- runValidationTB :: m (Validation err a)+data ValidationB m err a =+ ValidationB {+ runValidationB :: m (Validation err a) } -fmapValidationTB ::+fmapValidationB :: Functor f => (a -> b)- -> ValidationTB f err a- -> ValidationTB f err b-fmapValidationTB f (ValidationTB k) =- ValidationTB (fmap (fmap f) k)-{-# INLINE fmapValidationTB #-}+ -> ValidationB f err a+ -> ValidationB f err b+fmapValidationB f (ValidationB k) =+ ValidationB (fmap (fmap f) k)+{-# INLINE fmapValidationB #-} -instance Functor m => Functor (ValidationTB m err) where+instance Functor m => Functor (ValidationB m err) where fmap =- fmapValidationTB+ fmapValidationB -apValidationTB ::+apValidationB :: Apply f =>- ValidationTB f err (a -> b)- -> ValidationTB f err a- -> ValidationTB f err b-ValidationTB f `apValidationTB` ValidationTB a =- ValidationTB (liftF2 (<.>) f a)-{-# INLINE apValidationTB #-}+ ValidationB f err (a -> b)+ -> ValidationB f err a+ -> ValidationB f err b+ValidationB f `apValidationB` ValidationB a =+ ValidationB (liftF2 (<.>) f a)+{-# INLINE apValidationB #-} -instance Apply m => Apply (ValidationTB m err) where+instance Apply m => Apply (ValidationB m err) where (<.>) =- apValidationTB+ apValidationB -pureValidationTB ::+pureValidationB :: Applicative f => a- -> ValidationTB f err a-pureValidationTB =- ValidationTB . pure . pure-{-# INLINE pureValidationTB #-}+ -> ValidationB f err a+pureValidationB =+ ValidationB . pure . pure+{-# INLINE pureValidationB #-} -aplValidationTB ::+aplValidationB :: Applicative f =>- ValidationTB f err (a -> b)- -> ValidationTB f err a- -> ValidationTB f err b-ValidationTB f `aplValidationTB` ValidationTB a =- ValidationTB (liftA2 (<*>) f a)-{-# INLINE aplValidationTB #-}+ ValidationB f err (a -> b)+ -> ValidationB f err a+ -> ValidationB f err b+ValidationB f `aplValidationB` ValidationB a =+ ValidationB (liftA2 (<*>) f a)+{-# INLINE aplValidationB #-} -instance Applicative m => Applicative (ValidationTB m err) where+instance Applicative m => Applicative (ValidationB m err) where pure =- pureValidationTB+ pureValidationB (<*>) =- aplValidationTB+ aplValidationB -altValidationTB ::+altValidationB :: (Functor m, Monad m) =>- ValidationTB m err a- -> ValidationTB m err a- -> ValidationTB m err a-ValidationTB x `altValidationTB` ValidationTB y =- ValidationTB (x >>= \q -> case q of+ ValidationB m err a+ -> ValidationB m err a+ -> ValidationB m err a+ValidationB x `altValidationB` ValidationB y =+ ValidationB (x >>= \q -> case q of Failure _ -> y Success a -> return (Success a))-{-# INLINE altValidationTB #-}+{-# INLINE altValidationB #-} -instance (Functor m, Monad m) => Alt (ValidationTB m err) where+instance (Functor m, Monad m) => Alt (ValidationB m err) where (<!>) =- altValidationTB+ altValidationB -foldrValidationTB ::+foldrValidationB :: Foldable f => (a -> b -> b) -> b- -> ValidationTB f err a+ -> ValidationB f err a -> b-foldrValidationTB f z (ValidationTB x) =+foldrValidationB f z (ValidationB x) = foldr (flip (foldr f)) z x-{-# INLINE foldrValidationTB #-}+{-# INLINE foldrValidationB #-} -instance Foldable m => Foldable (ValidationTB m err) where+instance Foldable m => Foldable (ValidationB m err) where foldr =- foldrValidationTB+ foldrValidationB -traverseValidationTB ::+traverseValidationB :: (Traversable g, Applicative f) => (a -> f b)- -> ValidationTB g err a- -> f (ValidationTB g err b)-traverseValidationTB f (ValidationTB x) =- ValidationTB <$> traverse (traverse f) x-{-# INLINE traverseValidationTB #-}+ -> ValidationB g err a+ -> f (ValidationB g err b)+traverseValidationB f (ValidationB x) =+ ValidationB <$> traverse (traverse f) x+{-# INLINE traverseValidationB #-} -instance Traversable m => Traversable (ValidationTB m err) where+instance Traversable m => Traversable (ValidationB m err) where traverse =- traverseValidationTB+ traverseValidationB -bimapValidationTB ::+bimapValidationB :: Functor f => (err -> frr) -> (a -> b)- -> ValidationTB f err a- -> ValidationTB f frr b-bimapValidationTB f g (ValidationTB x) =- ValidationTB (fmap (bimap f g) x)-{-# INLINE bimapValidationTB #-}+ -> ValidationB f err a+ -> ValidationB f frr b+bimapValidationB f g (ValidationB x) =+ ValidationB (fmap (bimap f g) x)+{-# INLINE bimapValidationB #-} -instance Functor m => Bifunctor (ValidationTB m) where+instance Functor m => Bifunctor (ValidationB m) where bimap =- bimapValidationTB+ bimapValidationB -bifoldrValidationTB ::+bifoldrValidationB :: Foldable f => (err -> b -> b) -> (a -> b -> b) -> b- -> ValidationTB f err a+ -> ValidationB f err a -> b-bifoldrValidationTB f g z (ValidationTB x) =+bifoldrValidationB f g z (ValidationB x) = foldr (flip (bifoldr f g)) z x-{-# INLINE bifoldrValidationTB #-}+{-# INLINE bifoldrValidationB #-} -instance Foldable m => Bifoldable (ValidationTB m) where+instance Foldable m => Bifoldable (ValidationB m) where bifoldr =- bifoldrValidationTB+ bifoldrValidationB -bitraverseValidationTB ::+bitraverseValidationB :: (Traversable g, Applicative f) => (err -> f frr) -> (a -> f b)- -> ValidationTB g err a- -> f (ValidationTB g frr b)-bitraverseValidationTB f g (ValidationTB x) =- ValidationTB <$> traverse (bitraverse f g) x-{-# INLINE bitraverseValidationTB #-}+ -> ValidationB g err a+ -> f (ValidationB g frr b)+bitraverseValidationB f g (ValidationB x) =+ ValidationB <$> traverse (bitraverse f g) x+{-# INLINE bitraverseValidationB #-} -instance Traversable m => Bitraversable (ValidationTB m) where+instance Traversable m => Bitraversable (ValidationB m) where bitraverse =- bitraverseValidationTB+ bitraverseValidationB -bindValidationTB ::+bindValidationB :: Monad f =>- ValidationTB f err a- -> (a -> ValidationTB f err b)- -> ValidationTB f err b-ValidationTB v `bindValidationTB` f =- ValidationTB (v >>= \w -> case w of+ ValidationB f err a+ -> (a -> ValidationB f err b)+ -> ValidationB f err b+ValidationB v `bindValidationB` f =+ ValidationB (v >>= \w -> case w of Failure e -> return (Failure e)- Success a -> runValidationTB (f a))-{-# INLINE bindValidationTB #-}-instance (Apply m, Monad m) => Bind (ValidationTB m err) where+ Success a -> runValidationB (f a))+{-# INLINE bindValidationB #-}+instance (Apply m, Monad m) => Bind (ValidationB m err) where (>>-) =- bindValidationTB+ bindValidationB -returnValidationTB ::+returnValidationB :: Monad f => a- -> ValidationTB f err a-returnValidationTB =- ValidationTB . return . pure-{-# INLINE returnValidationTB #-}+ -> ValidationB f err a+returnValidationB =+ ValidationB . return . pure+{-# INLINE returnValidationB #-} -instance Monad m => Monad (ValidationTB m err) where+instance Monad m => Monad (ValidationB m err) where return =- returnValidationTB+ returnValidationB (>>=) =- bindValidationTB+ bindValidationB _ValidationV' :: Validate f =>@@ -747,11 +748,11 @@ {-# INLINE _ValidationV' #-} _ValidationTx ::- Iso (ValidationT e m a) (ValidationT e' m' a') (ValidationTB m e a) (ValidationTB m' e' a')+ Iso (ValidationT e m a) (ValidationT e' m' a') (ValidationB m e a) (ValidationB m' e' a') _ValidationTx = iso- (\(ValidationT x) -> ValidationTB x)- (\(ValidationTB x) -> ValidationT x)+ (\(ValidationT x) -> ValidationB x)+ (\(ValidationB x) -> ValidationT x) _AccValidationV :: Validate f =>@@ -912,14 +913,14 @@ Success e -> Failure e) {-# INLINE swappedValidation #-} -swappedValidationTB ::+swappedValidationB :: Functor k =>- Iso (ValidationTB k e a) (ValidationTB k f b) (ValidationTB k a e) (ValidationTB k b f)-swappedValidationTB =+ Iso (ValidationB k e a) (ValidationB k f b) (ValidationB k a e) (ValidationB k b f)+swappedValidationB = iso- (\(ValidationTB x) -> ValidationTB (fmap (swapped # ) x))- (\(ValidationTB x) -> ValidationTB (fmap (swapped # ) x))-{-# INLINE swappedValidationTB #-}+ (\(ValidationB x) -> ValidationB (fmap (swapped # ) x))+ (\(ValidationB x) -> ValidationB (fmap (swapped # ) x))+{-# INLINE swappedValidationB #-} instance Swapped AccValidation where swapped =@@ -929,6 +930,6 @@ swapped = swappedValidation -instance Functor f => Swapped (ValidationTB f) where+instance Functor f => Swapped (ValidationB f) where swapped =- swappedValidationTB+ swappedValidationB
validation.cabal view
@@ -1,25 +1,70 @@ name: validation-version: 0.4.3+version: 0.5.0 license: BSD3 license-file: LICENSE author: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart> maintainer: Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>-copyright: Copyright (C) 2014 NICTA Limited+copyright: Copyright (C) 2014,2015 NICTA Limited synopsis: A data-type like Either but with an accumulating Applicative category: Data description: <<http://i.imgur.com/Ns5hntl.jpg>> .- A data-type like Either but with an accumulating Applicative-homepage: https://github.com/tonymorris/validation-bug-reports: https://github.com/tonymorris/validation/issues+ Several data-types like Either but with differing properties and type-class+ instances.+ .+ Library support is provided for those different representations, include+ `lens`-related functions for converting between each and abstracting over their+ similarities.+ .+ * `AccValidation`+ .+ The `AccValidation` data type is isomorphic to `Either`, but has an instance+ of `Applicative` that accumulates on the error side. That is to say, if two+ (or more) errors are encountered, they are appended using a `Semigroup`+ operation.+ .+ As a consequence of this `Applicative` instance, there is no corresponding+ `Bind` or `Monad` instance. `AccValidation` is an example of, "An applicative+ functor that is not a monad."+ .+ * `Validation`+ .+ The `Validation` data type is isomorphic to `Either` and has a `Monad`+ instance that does the same as `Either`. The only difference to `Either` is+ the constructor names and surrounding library support.+ .+ * `ValidationT`+ .+ The `ValidationT` data type is the monad transformer for `Validation`. An+ instance of `MonadTrans` is provided for `(ValidationT err)`. Due to the+ arrangement of the `ValidationT` type constructor, which permits a `MonadTrans+ instance, there is no possible `Bifunctor` instance. Consequently, the+ `ValidationB` data type provides a `Bifunctor` instance (but not a+ `MonadTrans` instance). Library support is provided to exploit the isomorphism+ to `ValidationB`.+ .+ Note that since `AccValidation` is not a monad, there is also no corresponding+ monad transformer for this data type.+ .+ * `ValidationB`+ .+ The `ValidationB` data type is similar to the monad transformer for+ `Validation` (`ValidationT`), however, due to the arrangement of the+ `ValidationB` type constructor, which permits a `Bifunctor` instance, there is+ no possible `MonadTrans` instance. Consequently, the `ValidationT` data type+ provides a `MonadTrans` instance (but not a `Bifunctor` instance). Library+ support is provided to exploit the isomorphism to `ValidationT`.++homepage: https://github.com/NICTA/validation+bug-reports: https://github.com/NICTA/validation/issues cabal-version: >= 1.10 build-type: Custom extra-source-files: changelog source-repository head type: git- location: git@github.com:tonymorris/validation.git+ location: git@github.com:NICTA/validation.git flag small_base description: Choose the new, split-up base package.@@ -29,18 +74,19 @@ Haskell2010 build-depends:- base < 5 && >= 3- , semigroups >= 0.8+ base >= 3 && < 5+ , mtl >= 2.0 && < 2.3+ , semigroups >= 0.8 , semigroupoids >= 4.0- , bifunctors >= 3.0- , lens >= 4.0- , transformers >= 0.3.0.0+ , bifunctors >= 3.0+ , lens >= 4.0 && < 5+ , transformers >= 0.3 && < 0.5 ghc-options: -Wall default-extensions:- NoImplicitPrelude+ NoImplicitPrelude hs-source-dirs: src