@hackage validation1.2.1
A data-type like Either but with an accumulating Applicative
Categories
License
BSD-3-Clause
Maintainer
Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
Links
Versions
Installation
Tested Compilers
Dependencies (10)
- assoc >=1 && <2
- base >=4.11 && <5
- bifunctors >=5.5 && <6
- deepseq >=1.4.3 && <2
- lens >=4.0.5 && <6
- profunctors >=5 && <6 Show all…
Dependents (28)
@hackage/sv, @hackage/railroad, @hackage/sv-core, @cardano/ouroboros-consensus-cardano, @hackage/imprevu, @hackage/strongweak, Show all…
A data type like Either but with an accumulating Applicative instance.
Validation
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, and corresponding classes forFailureandSuccess) following the conventions ofmakeClassyandmakeClassyPrismsfromlens.Polymorphic prisms (
__Failure,__Success) for type-changing operations.Isomorphisms to
Eitherand(Bool, a).
Validator
The Validator newtype is a profunctor transformer:
newtype Validator e p x a = Validator (p x (Validation e a))
Validator e (->) x a is isomorphic to x -> Validation e a. The profunctor
parameter p generalises this to other optic-like contexts such as Tagged,
Iso, and Prism.
Instances include Functor, Apply, Applicative, Alt, Selective,
Profunctor, Strong, Choice, Semigroupoid, Category, Arrow,
ArrowApply, ArrowChoice, and Wrapped.
The Applicative instance accumulates errors in parallel (using Semigroup),
while Category composition short-circuits on Failure (like monadic bind).
The library also provides profunctor newtype wrappers (Iso'', Prism'') that
allow Validator to be parameterised over monomorphic isos and prisms.