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

Modulesemialign-1.3.1Haskell2010

Data.Align

These-based aligning and unaligning of functors with non-uniform shapes.

For a traversals traversal of (bi)foldable (bi)functors through said functors see Data.Crosswalk.

  • 3 classes
  • 8 values
  • Packagesemialign-1.3.1
  • Exports11
  • LanguageHaskell2010
  • LicenceBSD-3-Clause
  • SourceAlign.hs
classclass Functor f => Semialign (f :: Type -> Type) where
#

Functors supporting an align operation that takes the union of non-uniform shapes.

Minimal definition: either align or alignWith.

Laws

The laws of align and zip resemble lattice laws. There is a plenty of laws, but they are simply satisfied.

And an additional property if f is Foldable, which tries to enforce align-feel: neither values are duplicated nor lost.

Note: join f x = f x x

Idempotency

join align ≡ fmap (join These)

Commutativity

align x y ≡ swap <$> align y x

Associativity

align x (align y z) ≡ assoc <$> align (align x y) z

With

alignWith f a b ≡ f <$> align a b

Functoriality

align (f <$> x) (g <$> y) ≡ bimap f g <$> align x y

Alignedness, if f is Foldable

toList x ≡ toListOf (folded . here) (align x y)
         ≡ mapMaybe justHere (toList (align x y))

Methods

  • align :: f a -> f b -> f (These a b)

    Analogous to zip, combines two structures by taking the union of their shapes and using These to hold the elements.

  • alignWith :: (These a b -> c) -> f a -> f b -> f c

    Analogous to zipWith, combines two structures by taking the union of their shapes and combining the elements with the given function.

Instances18Semialign, …
classclass Semialign f => Align (f :: Type -> Type) where
#

A unit of align.

Laws

(`align` nil) ≡ fmap This
(nil `align`) ≡ fmap That

Methods

  • nil :: f a

    An empty structure. aligning with nil will produce a structure with the same shape and elements as the other input, modulo This or That.

Instances13Align, …
  • Align IntMapDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Align SeqDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Align ZipListDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Align MaybeDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Align VectorDefined in semialign-1.3.1 · Data.Semialign.Internal
  • Align []Defined in semialign-1.3.1 · Data.Semialign.Internal
  • Monad m => Align (Stream m)Defined in semialign-1.3.1 · Data.Semialign.Internal
  • Ord k => Align (Map k)Defined in semialign-1.3.1 · Data.Semialign.Internal
  • Align ProxyDefined in semialign-1.3.1 · Data.Semialign.Internal
  • (Eq k, Hashable k) => Align (HashMap k)Defined in semialign-1.3.1 · Data.Semialign.Internal
  • Monad m => Align (Bundle m v)Defined in semialign-1.3.1 · Data.Semialign.Internal
  • (Align f, Align g) => Align (Product f g)Defined in semialign-1.3.1 · Data.Semialign.Internal
  • (Align f, Semialign g) => Align (Compose f g)Defined in semialign-1.3.1 · Data.Semialign.Internal
classclass Semialign f => Unalign (f :: Type -> Type) where
#

Alignable functors supporting an "inverse" to align: splitting a union shape into its component parts.

Laws

uncurry align (unalign xs) ≡ xs
unalign (align xs ys) ≡ (xs, ys)

Compatibility note

In version 1 unalign was changed to return (f a, f b) pair, instead of (f (Just a), f (Just b)). Old behaviour can be achieved with if ever needed.

Example1 expression
unzipWith (unalign . Just) [This 'a', That 'b', These 'c' 'd']([Just 'a',Nothing,Just 'c'],[Nothing,Just 'b',Just 'd'])

Methods

Instances6Unalign

Specialized aligns

8 declarations