semialign

Align and Zip type-classes from the common Semialign ancestor.

https://github.com/haskellari/these

Version on this page:1.2.0.1@rev:3
LTS Haskell 22.37:1.3.1@rev:1
Stackage Nightly 2024-10-09:1.3.1@rev:1
Latest on Hackage:1.3.1@rev:1

See all snapshots semialign appears in

BSD-3-Clause licensed by C. McCann, Oleg Grenrus
Maintained by Oleg Grenrus
This version can be pinned in stack with:semialign-1.2.0.1@sha256:ee3468e349e72ec0a604ae05573a4de7181d97d10366254244a0cca8a76d6c35,2852

Module documentation for 1.2.0.1

The major use of These of this is provided by the align member of Semialign class, representing a generalized notion of "zipping with padding" that combines structures without truncating to the size of the smaller input.

It turns out that zip operation fits well the Semialign class, forming lattice-like structure.

Changes

1.2.0.1

  • GHC-9.2 support

1.2

  • Migrate SemialignWithIndex and ZipWithIndex to this package, using FunctorWithIndex from indexed-traversable.
  • Add RepeatWithIndex type-class.
  • Poly-kinded instances (notably Tagged)

1.1.0.1

  • Drop base-compat dependency

1.1

  • Split Semialign into Semialign and Zip.
  • Rename old Zip into Repeat
  • i.e. current main hierarchy is
  • Remove malign, use salign or alignWith mappend where Monoid is necessary.
  • Add Option instances
instance Functor f => Semialign f where
    alignWith :: (These a b -> c) -> f a -> f b -> f c

instance Semialign f => Align f where
    nil :: f a

instance Semialign f => Zip f where
    zipWith :: (a -> b -> c) -> f a -> f b -> f c

instance Zip f => Repeat f where
    repeat :: a -> f a

This biased choice, that Semialign is a super-class of Zip is motivated by the fact that

  • There’s no Semialign-like class anywhere else, yet
  • Zip and Repeat are Apply (from semigroupoids) and Applicative with slightly more laws. I If you need only Repeat class, and your type isn’t Alingable, maybe using Applicative is enough?

1

Split out of these package.