either-n: Data types like Either but with more constructors

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

Data types like Either but with more constructors, and optics for the constructors of any sum type.

Either3

Either3 a b c is a value of one of three types, with the constructors First3, Second3 and Third3. The Functor, Applicative and Monad instances act on the third type parameter, so First3 and Second3 short-circuit, in the same way Left does for Either.

Either3T

Either3T f a b c is an Either3 inside a type constructor f, in the same way that ExceptT e m a is m (Either e a). Use _Wrapped to convert between Either3T f a b c and f (Either3 a b c). The mtl classes are lifted from f.

Injections

Data.Lens.Injection provides the classes Injection1 to Injection19, the sum-type duals of Field1 to Field19 from lens. Where _1 is a lens to the first field of a product, _I1 is a prism to the first constructor of a sum. Each class has a default implementation for any type with a Generic instance.


[Skip to Readme]

Flags

Manual Flags

NameDescriptionDefault
doctest

Build the doctest test suite, which runs doctest through cabal. It is enabled in cabal.project, and disabled by default so that builds from the source distribution do not need cabal or doctest at test time.

Disabled

Use -f <flag> to enable a flag, or -f -<flag> to disable that flag. More info

Downloads

Maintainer's Corner

Package maintainers

For package maintainers and hackage trustees

Candidates

  • No Candidates
Versions [RSS] 0.1.0.0
Change log changelog.md
Dependencies assoc (>=1.1 && <2), base (>=4.18 && <5), deepseq (>=1.4.8.1 && <2), lens (>=5.2.1 && <6), mtl (>=2.3.1 && <2.4), selective (>=0.7 && <1), semigroupoids (>=6.0.0.1 && <7) [details]
Tested with ghc ==9.14.1, ghc ==9.12.4, ghc ==9.10.3, ghc ==9.8.4, ghc ==9.6.7
License BSD-3-Clause
Copyright Copyright (c) 2026 Tony Morris
Author Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Maintainer Tony Morris <ʇǝu˙sıɹɹoɯʇ@ןןǝʞsɐɥ> <dibblego>
Uploaded by TonyMorris at 2026-10-02T03:59:49Z
Category Data
Home page https://gitlab.com/tonymorris/either-n
Bug tracker https://gitlab.com/tonymorris/either-n/issues
Source repo head: git clone https://gitlab.com/tonymorris/either-n.git
Distributions
Reverse Dependencies 1 direct, 52 indirect [details]
Downloads 2 total (2 in the last 30 days)
Rating (no votes yet) [estimated by Bayesian average]
Your Rating
  • λ
  • λ
  • λ
Status Docs uploaded by user
Build status unknown [no reports yet]

Readme for either-n-0.1.0.0

[back to package description]

either-n

System F Logo

Data types like Either but with more constructors, and optics for the constructors of any sum type.

Download from hackage.

Either3

Either3 a b c is a value of one of three types:

data Either3 a b c
  = First3 a
  | Second3 b
  | Third3 c

The Functor, Applicative and Monad instances act on the third type parameter, so First3 and Second3 short-circuit, in the same way Left does for Either. The Bifunctor instances act on the second and third type parameters.

Either3T

Either3T f a b c is an Either3 inside a type constructor f, in the same way that ExceptT e m a is m (Either e a):

newtype Either3T f a b c = Either3T (f (Either3 a b c))

Use _Wrapped to convert between Either3T f a b c and f (Either3 a b c). The Monad instance requires Monad f, and MonadIO, MonadFail, MonadState, MonadReader, MonadWriter, MonadError, MonadRWS, MonadCont and MonadZip are lifted from f. either3Identity is the isomorphism between Either3 a b c and Either3T Identity a b c.

The type parameters are in the order f a b c so that Either3T f a is a Bifunctor. As a consequence, Either3T has no MonadTrans instance.

Injections

Data.Lens.Injection provides the classes Injection1 to Injection19, the sum-type duals of Field1 to Field19 from lens. Where _1 is a lens to the first field of a product, _I1 is a prism to the first constructor of a sum:

>>> (Left 1 :: Either Int String) ^? _I1
Just 1

>>> _I2 # True :: Either3 Int Bool String
Second3 True

Instances are provided for Either, Maybe, Bool, Ordering, lists, Identity, (), Data.Functor.Sum, GHC.Generics.:+:, Either3 and Either3T Identity. Each class has a default implementation for any type with a Generic instance, so an instance needs no body:

data T a = T1 a | T2 | T3 Int Bool
  deriving Generic

instance Injection1 (T a) (T b) a b
instance Injection2 (T a) (T a) () ()
instance Injection3 (T a) (T a) (Int, Bool) (Int, Bool)

A constructor with no fields has the focus (), a constructor with one field has that field as its focus, and a constructor with more than one field has any type with a single constructor with the same fields, such as a tuple, as its focus.