Package1.3.3Data
validation
A data-type like Either but with an accumulating Applicative
- Version1.3.3
- CategoryData
- LicenceBSD-3-Clause
- AuthorTony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
- MaintainerTony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
- Homepagegithub.com/system-f/validation
- Pinned byhackage validation 1.3.3
- Sourcehackage.haskell.org/package/validation-1.3.3
Modules
4 modules- Data.Validation0
- Data.Validation.Validation10A data type similar to Data.Either that accumulates failures.
- Data.Validation.ValidationMonad8A monad transformer wrapping m (Validation err a) with short-circuiting
- Data.Validation.Validator30
Description
A data type like Either but with an accumulating Applicative instance.
The Validation 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. Validation is an example of, "An applicative functor that is not a monad."
The library provides:
Classy optics (GetValidation, HasValidation, ReviewValidation, AsValidation) following the conventions of makeClassy and makeClassyPrisms from lens. Polymorphic prisms (__Failure, __Success) for type-changing operations. Isomorphisms to Either and (Bool, a).
ValidationMonadT err m a is a monad transformer wrapping m (Validation err a). Unlike Validation, it has short-circuiting Applicative, Bind, Monad, and MonadError instances.
Four validator newtypes wrap a validation function with different type parameter orders, enabling different class instances:
Validator x err a — Bifunctor, accumulating Applicative, Either-like Alt ValidatorProfunctor err x a — Profunctor, accumulating Applicative ValidatorMonadT x err f a — Monad, MonadTrans, BindTrans ValidatorMonadProfunctorT err f x a — Profunctor, Monad, Category, Arrow
All four are isomorphic and have cross-type optics instances.
Validator is the odd one out in its Alt instance. For the other three validators, <!> accumulates errors when both sides fail. For Validator, <!> behaves like Either: the first success wins, otherwise the second failure is returned. Validator has no Plus or Alternative instance, and its <> still accumulates errors.
Depends on
11 packages- assoc-1.1.1in this set
- base-4.22.0.0with GHC
- bifunctors-5.6.3in this set
- deepseq-1.5.1.0with GHC
- either-n-0.1.0.0in this set
- lens-5.3.6in this set
- mtl-2.3.1with GHC
- profunctors-5.6.3in this set
- selective-0.7.0.1in this set
- semigroupoids-6.0.2in this set
- transformers-0.6.1.2with GHC
Used by in this set · 0
Nothing in this set depends on it.