Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Introduce the right Kan extension #31

Merged
merged 1 commit into from
Aug 5, 2018

Conversation

joneshf
Copy link
Contributor

@joneshf joneshf commented Aug 2, 2018

Re: #30

First go an implementing Ran f g a. There's more that could be moved from Codensity/Yoneda, but requires some additional concepts. E.g.

  • We could define Applicative (Ran f g) if we have a an isomorphism between f and g (or at least forall (a : Type) -> f a -> g a and forall (a : Type) -> g a -> f a).
  • We could define Ran/lower if we have forall (a : Type) -> f a -> a (I think).

I didn't want to add these just things for the sake of redefining everything in terms of Ran, but can if they're wanted.

In any case, let me know if this is what we're thinking and if anything needs to change!

Kan extensions are a way to take two functors `f` and `g`
and make a third that "extends" `f`s domain along `g`.
There are a few transformations from the canonical definition
of the right Kan extension to the definition here,
but this formulation should be equivalent.

Many people have said Kan extensions are the most universal constructions.
We show that here by defining Codensity and Yoneda in terms of Ran.
Copy link
Contributor

@FintanH FintanH left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This LGTM

@joneshf
Copy link
Contributor Author

joneshf commented Aug 5, 2018

Given this comment, maybe it should be Ran/Covariant/Type? And also add Ran/Contravariant/Type as:

(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 (b : Type)  (f b  a)  g b

@FintanH
Copy link
Contributor

FintanH commented Aug 5, 2018

I think since it's a standalone concept and would just cause code duplication I'll merge as is. I believe Contravariant and Covariant idea just applies to things that have those distinguishable characteristics.

@FintanH FintanH merged commit 78253e6 into FormationAI:master Aug 5, 2018
@joneshf joneshf deleted the right-kan-extension branch August 5, 2018 16:20
@joneshf
Copy link
Contributor Author

joneshf commented Aug 5, 2018

Oh, sorry for being unclear. The two are different.

Ran/Covariant/Type

(f : Type  Type)  (g : Type  Type)  (a : Type)  Type
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 (b : Type)
 (a  f b)
 g b

Ran/Contravariant/Type

(f : Type  Type)  (g : Type  Type)  (a : Type)  Type
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 (b : Type)
 (f b  a)
 g b

N.B. (a → f b) vs. (f b → a).

The derived types end up being similarly defined, but over their variance:

Yoneda/Covariant/Type

(f : Type  Type)  (a : Type)  Type
./../../Ran/Covariant/Type ./../../Id/Type

Yoneda/Contravariant/Type

(f : Type  Type)  (a : Type)  Type
./../../Ran/Contravariant/Type ./../../Id/Type

It makes an impact in expressions like lift and lower

Ran/Covariant/lift

(f : Type  Type)
 (g : Type  Type)
 (a : Type)
 ./../../Comonad/Type f
 ./../../Functor/Type g
 g a
 ./Type f g a
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 λ(comonad : ./../../Comonad/Type f)
 λ(functor : ./../../Functor/Type g)
 λ(x : g a)
 λ(b : Type)
 λ(k : a  f b)
 functor.map a b (λ(y : a)  comonad.extract b (k y)) x

Ran/Contravariant/lift

(f : Type  Type)
 (g : Type  Type)
 (a : Type)
 ./../../Applicative/Type f
 ./../../Contravariant/Type g
 g a
 ./Type f g a
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 λ(applicative : ./../../Applicative/Type f)
 λ(contravariant : ./../../Contravariant/Type g)
 λ(x : g a)
 λ(b : Type)
 λ(k : f b  a)
 contravariant.map a b (λ(y : b)  k (applicative.pure b y)) x

Ran/Covariant/lower

(f : Type  Type)
 (g : Type  Type)
 (a : Type)
 ./../../Applicative/Type f
 ./Type f g a
 g a
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 λ(applicative : ./../../Applicative/Type f)
 λ(ran : ./Type f g a)
 ran a (applicative.pure a)

Ran/Contravariant/lower

(f : Type  Type)
 (g : Type  Type)
 (a : Type)
 ./../../Comonad/Type f
 ./Type f g a
 g a
λ(f : Type  Type)
 λ(g : Type  Type)
 λ(a : Type)
 λ(comonad : ./../../Comonad/Type f)
 λ(ran : ./Type f g a)
 ran a (comonad.extract a)

I.e. Where one version requires Applicative f, the other version requires Comonad f. Similarly for Functor f and Contravariant f.

Ends up with a version of Codensity, Yoneda, etc for both covariant and contravariant types.

I'm down to submit a PR, if that seems useful.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants