Skip to content

Comments

[ add ] filter-∩, filter-map and filter-swap for Data.List.Properties#2942

Merged
jamesmckinna merged 5 commits intoagda:masterfrom
IchiganCS:filter-intersection
Feb 17, 2026
Merged

[ add ] filter-∩, filter-map and filter-swap for Data.List.Properties#2942
jamesmckinna merged 5 commits intoagda:masterfrom
IchiganCS:filter-intersection

Conversation

@IchiganCS
Copy link
Contributor

@IchiganCS IchiganCS commented Feb 14, 2026

I recently was surprised that the standard library doesn't prove these two laws, so I quickly added them.

filter-∩    : filter (P? ∩? Q?) ≗ filter P? ∘ filter Q?
filter-swap : filter P? ∘ filter Q? ≗ filter Q? ∘ filter P?

I hope I followed all guidelines etc.
There is one thing where opinions can differ in style: filter-swap could either be proven by directly pattern matching on P? x and Q? x respectively, but I feel like using propositional equality is more elegant. The downside is the additional module definition (which could maybe be written differently? - I'm new to Agda).

Edit:

map-filter-swap   :  {P : Pred B p} (f : A  B) (p? : Decidable₁ P) 
                     filter p? ∘ map f ≗ map f ∘ filter (p? ∘ f)

would also be a nice addition.

Copy link
Collaborator

@jamesmckinna jamesmckinna left a comment

Choose a reason for hiding this comment

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

Thanks very much for the first PR!

With some suggestions for streamlining your submitted code.

@jamesmckinna
Copy link
Collaborator

As for your proposed

map-filter-swap   :  {P : Pred B p} (f : A  B) (p? : Decidable₁ P) 
                     filter p? ∘ map f ≗ map f ∘ filter (p? ∘ f)

would also be a nice addition.

That seems good, too, but think that filter-map would be a name more in line with our conventions.

As for direct-style proofs vs. appeal to existing lemmas, and use of function equalities, the latter as you have chosen, does seem nice. If there are opportunities to refactor later, the let's do that later. For now, a nice first contribution!

* also introduced minor readibility rewrites for `filter-∩`  and `filter-swap`
@IchiganCS
Copy link
Contributor Author

I added the filter-map (much better name, true) and also integrated the minor readability fixes you suggested - thanks for your kind suggestions!

@IchiganCS IchiganCS changed the title [ add ] filter-∩ and filter-swap for Data.List.Properties [ add ] filter-∩, filter-map and filter-swap for Data.List.Properties Feb 15, 2026
@jamesmckinna
Copy link
Collaborator

And you'll need to add a CHANGELOG entry with the new additions...

@IchiganCS
Copy link
Contributor Author

Sorry for that oversight - i was so eager to install fix-whitespace and run it that I forgot that -_-

Done now! Sorry for the many commits, I think squashing them would be best.

@jamesmckinna
Copy link
Collaborator

Sorry for that oversight - i was so eager to install fix-whitespace and run it that I forgot that -_-

Done now! Sorry for the many commits, I think squashing them would be best.

We squash on merge.

CHANGELOG.md Outdated
Comment on lines 264 to 266
filter-map : (f : B → A) → filter P? ∘ map f ≗ map f ∘ filter (P? ∘ f)
filter-∩ : filter (P? ∩? Q?) ≗ filter P? ∘ filter Q?
filter-swap : filter P? ∘ filter Q? ≗ filter Q? ∘ filter P?
Copy link
Collaborator

Choose a reason for hiding this comment

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

Two quick nit picks:

  • for each block of additions, we tend to align the : for readability
  • just as for the second and third, there's no need to mention the quantification over P?, Q? etc., neither is it really necessary to mention the f binding in the first one...

The last point may be more of an individual opinion than canon, but AFAIAC, the reader who wants to know the details of implicit vs. explicit quantification can, and will do so in the source. At the current moment of writing, we don't attempt to machine-check any validity criteria for CHANGELOGs, so they can only be considered advisory, rather than definitive!

@jamesmckinna jamesmckinna added this to the v2.4 milestone Feb 16, 2026
Co-authored-by: jamesmckinna <31931406+jamesmckinna@users.noreply.github.com>
@jamesmckinna jamesmckinna added this pull request to the merge queue Feb 17, 2026
Merged via the queue into agda:master with commit 61903c8 Feb 17, 2026
12 checks passed
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.

3 participants