validation: A data-type like Either but with an accumulating Applicative

[ bsd3, data, library ] [ Propose Tags ] [ Report a vulnerability ]

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) following the conventions of makeClassy and makeClassyPrisms from lens.

  • Polymorphic prisms (__Failure, __Success) for type-changing operations.

  • Isomorphisms to Either and (Bool, a).

ValidationMonadT

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.

Validators

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.

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

Versions [RSS] 0.3.0, 0.3.1, 0.3.2, 0.3.3, 0.3.4, 0.4.0, 0.4.1, 0.4.2, 0.4.3, 0.5.0, 0.5.1, 0.5.2, 0.5.3, 0.5.4, 0.5.5, 0.6.0, 0.6.1, 0.6.2, 0.6.3, 1, 1.1, 1.1.1, 1.1.2, 1.1.3, 1.1.4, 1.1.5, 1.2.0, 1.2.1, 1.2.2, 1.3.0, 1.3.1, 1.3.2, 1.3.3
Change log changelog
Dependencies assoc (>=1.1 && <2), base (>=4.18 && <5), bifunctors (>=5.6 && <6), deepseq (>=1.4.8.1 && <2), either-n (>=0.1 && <0.2), lens (>=5.2.1 && <6), mtl (>=2.3.1 && <2.4), profunctors (>=5.6.2 && <6), selective (>=0.7 && <1), semigroupoids (>=6.0.0.1 && <7), transformers (>=0.6.1.0 && <0.7) [details]
Tested with ghc ==9.10.3, ghc ==9.8.4, ghc ==9.6.7
License BSD-3-Clause
Copyright Copyright (C) 2010-2013 Tony Morris, Nick Partridge Copyright (C) 2014,2015 NICTA Limited Copyright (c) 2016-2019 Commonwealth Scientific and Industrial Research Organisation (CSIRO) ABN 41 687 119 230 Copyright (c) 2019-2026 Tony Morris
Author Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
Maintainer Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>, Nick Partridge <nkpart>
Uploaded by TonyMorris at 2026-10-02T04:33:19Z
Category Data
Home page https://github.com/system-f/validation
Bug tracker https://github.com/system-f/validation/issues
Source repo head: git clone git@github.com:system-f/validation.git
Distributions LTSHaskell:1.1.5, Stackage:1.3.3
Reverse Dependencies 24 direct, 28 indirect [details]
Downloads 27651 total (148 in the last 30 days)
Rating 2.5 (votes: 3) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs available [build log]
Last success reported on 2026-10-02 [all 1 reports]