HORIZON HASKELLDocslts/ghc-10.0.x2b276322026-10-31Search packagesCtrl K
Theme: |

GHC 10.0.0.20260917 · lts/ghc-10.0.x · 2b27632 · 2026-10-31

Modulethese-1.2.1Haskell2010

Data.These

The These type and associated operations.

Contents
  1. Functions to get rid of These
  2. Partition
  3. Distributivity
Synopsis
  • Packagethese-1.2.1
  • Exports12
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceThese.hs
datadata These a b

The These type represents values with two non-exclusive possibilities.

This can be useful to represent combinations of two values, where the combination is defined if either input is. Algebraically, the type These A B represents (A + B + AB), which doesn't factor easily into sums and products--a type like Either A (B, Maybe A) is unclear and awkward to use.

These has straightforward instances of Functor, Monad, &c., and behaves like a hybrid error/writer monad, as would be expected.

For zipping and unzipping of structures with These values, see Data.Align.

Constructors

Instances36Bifoldable, Bifoldable1, Bifunctor, Bitraversable, Eq2, Ord2, …

Functions to get rid of These

valuethese :: (a -> c) -> (b -> c) -> (a -> b -> c) -> These a b -> c

Case analysis for the These type.

valuefromThese :: a -> b -> These a b -> (a, b)

Takes two default values and produces a tuple.

Partition

valuepartitionThese :: [These a b] -> ([a], [b], [(a, b)])

Select each constructor and partition them into separate lists.

Like partitionEithers but for NonEmpty types.

Note: this is not online algorithm. In the worst case it will traverse the whole list before deciding the result constructor.

Example1 expression
partitionEithersNE $ Left 'x' :| [Right 'y']These ('x' :| "") ('y' :| "")
Example1 expression
partitionEithersNE $ Left 'x' :| map Left "yz"This ('x' :| "yz")

Distributivity

These distributivity combinators aren't isomorphisms!