Kan extensions, Kan lifts, the Yoneda lemma, and (co)density (co)monads


LTS Haskell 22.30:5.2.6
Stackage Nightly 2024-07-24:5.2.6
Latest on Hackage:5.2.6

See all snapshots kan-extensions appears in

BSD-3-Clause licensed by Edward A. Kmett
Maintained by Edward A. Kmett
This version can be pinned in stack with:kan-extensions-5.2.6@sha256:52f1ac209f9f8f7f1eaa3195a0e5592b45067c2362312e718414733b32ae9fe9,2481


Hackage Build Status

This package provides tools for working with various Kan extensions and Kan lifts in Haskell.

Among the interesting bits included are:

  • Right and left Kan extensions (Ran and Lan)
  • Right and left Kan lifts (Rift and Lift)
  • Multiple forms of the Yoneda lemma (Yoneda)
  • The Codensity monad, which can be used to improve the asymptotic complexity of code over free monads (Codensity, Density)
  • A “comonad to monad-transformer transformer” that is a special case of a right Kan lift. (CoT, Co)

Contact Information

Contributions and bug reports are welcome!

Please feel free to contact me through github or on the #haskell IRC channel on irc.freenode.net.

-Edward Kmett


5.2.6 [2024.05.04]

  • Drop support for GHC 8.2 and earlier.

  • Generalize instances in Control.Monad.Codensity to be of the form:

    instance (f ~~ f', MonadFail f') => MonadFail (Codensity (f :: k -> TYPE rep))

    This avoids having to constrain k ~ Type and rep ~ LiftedRep, which could potentially harm type inference.

  • Explicitly implement liftA2 in the Applicative instance for Data.Functor.Day.Curried.

  • Add an Adjunction instance for Data.Functor.Day.

  • Add Adjunction and Divisible instances for Data.Functor.Contravariant.Day.

  • Add an Apply instance for Data.Functor.Day.Curried.

5.2.5 [2022.06.26]

  • Only require a Functor constraint in the Eq and Ord instances for Coyoneda when building against transformers-0.4.*.

5.2.4 [2022.05.07]

  • Allow building with transformers-0.6.* and mtl-2.3.*.

5.2.3 [2021.07.27]

  • Add shift and reset to Control.Monad.Codensity.

5.2.2 [2021.02.17]

  • Add hoistCoyoneda to Data.Functor.Contravariant.Coyoneda.

5.2.1 [2020.10.01]

  • Allow building with GHC 9.0.

5.2 [2018.07.03]

  • Make Codensity levity polymorphic.
  • Add the Data.Functor.Invariant.Day module, which combines the covariant and contravariant versions of Day. As a result, kan-extensions now depends on the invariant package.
  • Add a wrapCodensity function.
  • More efficient Eq1, Ord1, and Adjunction instances for Coyoneda.
  • Add INLINE pragmas on more functions.
  • Allow building with containers-0.6.

5.1 [2018.01.28]

  • Make Density, Codensity, Kan and Lan polykinded.
  • Add Eq1, Ord1, Read1 and Show1 instances for Coyoneda and Yoneda.
  • Change contexts of Eq and Ord instances of Coyoneda and Yoneda (and the Show instance for Coyoneda) to require lifted class instances, e.g. Eq1 f, Eq a.
  • Allow free-5.


  • Added hoistCoyoneda


  • Removed some redundant constraints


  • Move Data.Functor.Kan.Rift to Data.Functor.Day.Curried


  • Builds clean on GHC 7.10


  • semigroupoids 5 support


  • Add liftRift and lowerRift


  • Remove pointed dependency


  • Added Applicative instance for Day
  • Added Typeable instance for Codensity

  • Added tagged dependency


  • Moved co- and contra- variant Day convolution from contravariant to here. Day convolution is intimately connected to Rift.


  • Added liftCoT0M, liftCoT1M, diter and dctrlM for using CoT w m to model a state machine with states in w and effects in m.


  • Made fixes necessary to work around changes in ImpredicativeTypes for GHC 7.8.1rc2


  • Bug fix so we can compile on GHC 7.4


  • Removed keys dependency
  • Now compatible with adjunctions 4.0


  • Moved all the Yoneda variants around again.
  • Improved haddocks


  • Added Data.Functor.Contravariant.Yoneda to complete the set of Yoneda embeddings/reductions.


  • Added several missing isomorphisms


  • instance Monad m => MonadSpec (Yoneda m)


  • Fixed a bug in the signature for composedRepToCodensity.


  • More combinators for Rift/Lift.
  • Added combinators for working with representable functors rather than just adjoint functors.
  • Split Data.Functor.KanExtension into Data.Functor.Kan.Ran and Data.Functor.Kan.Lan
  • Split Data.Functor.KanLift into Data.Functor.Kan.Rift and Data.Functor.Kan.Lift
  • Moved from Data.Functor.Yoneda.Contravariant to Data.Functor.Yoneda.Reduction adopting terminology from Todd Trimble.
  • Added various missing isomorphisms.
  • Greatly improved the Haddocks for this package stating laws and derivations where we can (especially for ‘Rift’ and ‘Ran’).


  • Rift is now Applicative. Added rap.


  • Added right and left Kan lifts under Data.Functor.KanLift.
  • Decreased reliance on the Composition class where unnecessary in the API


  • Marked modules Trustworthy as required for SafeHaskell in the presence of these extensions.


  • Refactored build system
  • IRC build-bot notification
  • Removed upper bounds on dependencies on my other packages


  • Moved Control.Monad.Free.Church over to the free package instead and removed it from kan-extensions