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 partition-is-foldr to Data.List.Properties #2505

Merged
merged 2 commits into from
Nov 28, 2024

Conversation

carlostome
Copy link
Contributor

No description provided.

@jamesmckinna
Copy link
Contributor

jamesmckinna commented Nov 27, 2024

Looks good to me. Thanks for the contribution!
But NB #2423 and its antecedents #2365 #2359 etc. Would this proof simplify if we could successfully refactor the definition of partition? UPDATED: I tried it, and apparently not. Oh well.

@gallais
Copy link
Member

gallais commented Nov 28, 2024

My only worry is that given that foldr can encode any function, should we have such a
lemma no matter how complex the cons step is? Relatedly, do we want to simplify this
one by defining e.g.

inj : Bool → A → A ⊎ A
_⊎∷_ : A ⊎ B → List A × List B → List A × List B

partition P? = foldr (\ x -> inj (does P? x) x ⊎∷_) ([], [])

@jamesmckinna
Copy link
Contributor

@gallais

I think there is indeed a question as why the definitions are given in Data.List.Base are given in 'plain' form, and not as instances of fold, but given that they are, it makes/made sense to me to accompany each of them with a lemma of this kind. But if we are going to widen the discussion to consider all of those definitions in the library, then... maybe a separate library-design issue worth opening?

As for the (straw-man?) refactoring you propose, I think it falls to Occam's Razor?

@JacquesCarette
Copy link
Contributor

I wouldn't call this partition-is-foldr but partition-as-foldr , or partition-via-foldr. And yes, foldr being the List eliminator, we need to be careful to not have an explosion of these. Having said that, I'm fine with partition as it is an important function.

@jamesmckinna
Copy link
Contributor

I wouldn't call this partition-is-foldr but partition-as-foldr , or partition-via-foldr. And yes, foldr being the List eliminator, we need to be careful to not have an explosion of these. Having said that, I'm fine with partition as it is an important function.

But we already have

  • id-is-foldr
  • ++-is-foldr
  • map-is-foldr
  • ...

So it does explode into a deprecation-fest if we follow your lead? v3.0?

@JacquesCarette
Copy link
Contributor

Sigh - yes, v3.0. Inconsistency is worse than misleading names.

@jamesmckinna jamesmckinna added this pull request to the merge queue Nov 28, 2024
Merged via the queue into agda:master with commit 23a00fd Nov 28, 2024
2 checks 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.

4 participants