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 a property relating maybe to composition #2414

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open

Conversation

WhatisRT
Copy link

This is part of upstreaming properties that seem generally useful.

Copy link
Contributor

@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.

You'll need to add to CHANGELOG too. But it is a nice little lemma that does seem to be missing, AFAIK.

@@ -97,6 +97,10 @@ maybe′-map : ∀ j (n : C) (f : A → B) ma →
maybe′ j n (map f ma) ≡ maybe′ (j ∘′ f) n ma
maybe′-map = maybe-map

maybe-∘ : ∀ {c x} (f : B → C) (g : A → B) → f (maybe g c x) ≡ maybe (f ∘ g) (f c) x
maybe-∘ {x = just _} _ _ = refl
Copy link
Contributor

Choose a reason for hiding this comment

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

Pattern-matching on an implicit argument like this doesn't quite smell right... and in any case, this lemma can probably (better) be given a direct one-line definition, again in terms of maybe...?

Copy link
Contributor

Choose a reason for hiding this comment

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

Also, on the model of maybe′-map, should the lemma be stated (and named) explicitly involving maybe′ rather than maybe?

Copy link
Author

Choose a reason for hiding this comment

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

Here's a proof that uses maybe instead of matching. I think it's clearly worse, and I don't think it can be reduced further:

maybe-∘ {x = x} f _ = maybe {B = λ y → f (maybe _ _ y) ≡ maybe _ _ y} (λ _ → refl) refl x

I don't mind converting x to an explicit argument, but there's plenty of good reasons to match on a hidden one, so I don't see that as a reason to do so.

Copy link
Contributor

@jamesmckinna jamesmckinna Jun 24, 2024

Choose a reason for hiding this comment

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

Well FWIW I guess I had had something in mind along the lines of

maybe′-∘ :  {b} (f : B  C) (g : A  B) x  f (maybe′ g b x) ≡ maybe′ (f ∘ g) (f b) x
maybe′-∘ _ _ = maybe (λ x  refl) refl

instead?

Mind you, I agree that it is very irritating that Agda finds this version easy to typecheck without having to provide the {B = ...} argument to maybe on the RHS, whereas your version above does not, all for the sake of a permuted argument list... :-(

Copy link
Contributor

Choose a reason for hiding this comment

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

Or even (better?):

maybe′-∘ :  {b} (f : B  C) (g : A  B)  f ∘ (maybe′ g b) ≗ maybe′ (f ∘ g) (f b)
maybe′-∘ _ _ = maybe (λ _  refl) refl

Copy link
Author

Choose a reason for hiding this comment

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

Hmm, I'm not sure it's worth weakening the resulting statement just so that the proof is a bit simpler. And arguably it's not even actually simpler (up to inlining), it's just a difference in the surface language code.

Copy link
Contributor

Choose a reason for hiding this comment

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

Not sure I understand how this is 'weaker' as a statement? In any downstream client use where f and/or g might depend on a given x, then appropriate arguments to the lemma can still be supplied, or not? Their types don't depend on x, so each of the arguments is 'independent' in the telescope?

Copy link
Author

Choose a reason for hiding this comment

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

Ah, yes, I was confused. We're not actually using the more general type of maybe here.

@jamesmckinna
Copy link
Contributor

And as for CHANGELOG... suggest this wait until this has been reset for the v2.2 milestone after the planned v2.1 release...

@jamesmckinna jamesmckinna added this to the v2.2 milestone Jun 23, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants