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

add kleisli triple #381

Merged
merged 4 commits into from
Aug 2, 2023
Merged

add kleisli triple #381

merged 4 commits into from
Aug 2, 2023

Conversation

Reijix
Copy link
Contributor

@Reijix Reijix commented Jul 27, 2023

Small proof that kleisli triples are equivalent to monads. I'm looking for some feedback and then I'd do the same for comonads.

I've defined the kleisli-triple as a typedef for RMonad idF to avoid redundancy, but this might make things a little unclear.

Copy link
Collaborator

@JacquesCarette JacquesCarette left a comment

Choose a reason for hiding this comment

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

Very nice - just a few minor things to tweak.

-- see https://ncatlab.org/nlab/show/extension+system (the naming differs)

open import Level
open import Categories.Category
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you please use Categories.Category.Core (unless you really need more) and also using clauses and and for all open import below.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Sure, fixed it!

open MR C

-- a kleisli triple is a relative monad with J = idF
Kleisli : Set (o ⊔ ℓ ⊔ e)
Copy link
Collaborator

Choose a reason for hiding this comment

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

I'm wondering if the type should be called KleisliTriple as there are too many Kleisli things already? (The implication below can keep its name)

Copy link
Collaborator

Choose a reason for hiding this comment

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

As a slightly polemic point, nLab seems to promote the name "extension system" https://ncatlab.org/nlab/show/extension+system. I am more used to the name "Kleisli triple", but nLab may well change the trend. I do not really have any opinion on this.

Copy link
Collaborator

Choose a reason for hiding this comment

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

I would be fine with either KleisliTriple or ExtensionSystem.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I chose KleisliTriple and KleisliCotriple for now.

module η = NaturalTransformation η

assoc' : ∀ {X : Obj} → μ.η X ∘ F₁ (μ.η X) ≈ μ.η X ∘ μ.η (F₀ X)
assoc' = begin
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is the exact same proof as commute above -- factor out please.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Done, I wasn't sure about the naming, so i just named it commute' and added a comment.

μ = ntHelper {F = F ∘F F} {G = F} record
{ η = λ X → extend id
; commute = λ f → begin
extend id ∘ extend (unit ∘ extend (unit ∘ f)) ≈⟨ sym K.assoc ⟩
Copy link
Collaborator

Choose a reason for hiding this comment

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

This repeated use of sym K.assoc makes me think that RelativeMonad should be extended to have sym-assoc in its API (this is optional, but would be nice).

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Changed it for RelativeMonad and RelativeComonad and also fixed places where its used.

identityʳ' : ∀ {X Y} {k : X ⇒ F₀ Y} → (μ.η Y ∘ F₁ k) ∘ η.η X ≈ k
identityʳ' {X} {Y} {k} = begin
((μ.η Y ∘ F₁ k) ∘ η.η X) ≈⟨ pullʳ (sym (η.commute _)) ⟩
(μ.η Y ∘ η.η (F₀ Y) ∘ k) ≈⟨ pullˡ M.identityʳ ⟩
Copy link
Collaborator

Choose a reason for hiding this comment

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

cancelˡ M.identityʳ should cut out 1 line.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Yup, thanks!

@Reijix Reijix marked this pull request as ready for review July 31, 2023 17:35
@Reijix
Copy link
Contributor Author

Reijix commented Jul 31, 2023

Thanks for the feedback! I've also added Categories.Comonad.Construction.CoKleisli now.

@JacquesCarette JacquesCarette merged commit 84840a5 into agda:master Aug 2, 2023
1 check passed
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.

3 participants