HORIZON HASKELLDocslts/ghc-9.10.xc74966e2026-09-27Search names, modules, packages, or :: a typeCtrl K

GHC 9.10.3 · lts/ghc-9.10.x · c74966e · 2026-09-27

Modulethese-1.2.1Haskell2010

Data.These

The These type and associated operations.

  • 1 type
  • 11 values
  • 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

4 declarations
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.

valuemergeThese :: (a -> a -> a) -> These a a -> a
#

Coalesce with the provided operation.

valuemergeTheseWith :: (a -> c) -> (b -> c) -> (c -> c -> c) -> These a b -> c
#

bimap and coalesce results with the provided operation.

Partition

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

Select each constructor and partition them into separate lists.

valuepartitionHereThere :: [These a b] -> ([a], [b])
#

Select here and there elements 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

4 declarations

These distributivity combinators aren't isomorphisms!