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

Modulekan-extensions-5.2.7Haskell2010

Data.Functor.Kan.Ran

  • Right Kan Extensions

  • 1 type
  • 13 values
newtypenewtype Ran (g :: k -> Type) (h :: k -> Type) a
#

The right Kan extension of a Functor h along a Functor g.

We can define a right Kan extension in several ways. The definition here is obtained by reading off the definition in of a right Kan extension in terms of an End, but we can derive an equivalent definition from the universal property.

Given a Functor h : C -> D and a Functor g : C -> C', we want to extend h back along g to give Ran g h : C' -> D, such that the natural transformation gran :: Ran g h (g a) -> h a exists.

In some sense this is trying to approximate the inverse of g by using one of its adjoints, because if the adjoint and the inverse both exist, they match!

Hask -h-> Hask
  |       +
  g      /
  |    Ran g h
  v    /
Hask -'

The Right Kan extension is unique (up to isomorphism) by taking this as its universal property.

That is to say given any K : C' -> D such that we have a natural transformation from k.g to h (forall x. k (g x) -> h x) there exists a canonical natural transformation from k to Ran g h. (forall x. k x -> Ran g h x).

We could literally read this off as a valid Rank-3 definition for Ran:

data Ran' g h a = forall z. Functor z => Ran' (forall x. z (g x) -> h x) (z a)

This definition is isomorphic the simpler Rank-2 definition we use below as witnessed by the

ranIso1 :: Ran g f x -> Ran' g f x
ranIso1 (Ran e) = Ran' e id
ranIso2 :: Ran' g f x -> Ran g f x
ranIso2 (Ran' h z) = Ran $ \k -> h (k <$> z)
ranIso2 (ranIso1 (Ran e)) ≡ -- by definition
ranIso2 (Ran' e id) ≡       -- by definition
Ran $ \k -> e (k <$> id)    -- by definition
Ran $ \k -> e (k . id)      -- f . id = f
Ran $ \k -> e k             -- eta reduction
Ran e

The other direction is left as an exercise for the reader.

Constructors

  • Ran
    • runRan :: forall (b :: k). (a -> g b) -> h b
Instances1Functor
  • Functor (Ran g h)Defined in kan-extensions-5.2.7 · Data.Functor.Kan.Ran
valuetoRan
  1. :: Functor k2
  2. => forall (a :: k1). k2 (g a) -> h a
  3. -> k2 b
  4. -> Ran g h b
#

The universal property of a right Kan extension.

valuegran :: Ran g h (g a) -> h a
#

This is the natural transformation that defines a Right Kan extension.