Skip to content

Add whenMissing, which takes user-supplied fns#1185

Open
meooow25 wants to merge 1 commit intohaskell:masterfrom
meooow25:whenmissing
Open

Add whenMissing, which takes user-supplied fns#1185
meooow25 wants to merge 1 commit intohaskell:masterfrom
meooow25:whenmissing

Conversation

@meooow25
Copy link
Copy Markdown
Contributor

This allows for some useful applications which are currently not possible with the non-internal API. The functions carry a warning that the two input functions are related by a law and the user is responsible for satisfying it.

Export filterA for Set, now that it is referred to from whenMissing.

Closes #1054

This allows for some useful applications which are currently not possible
with the non-internal API. The functions carry a warning that the two
input functions are related by a law and the user is responsible for
satisfying it.

Export filterA for Set, now that it is referred to from whenMissing.
@meooow25
Copy link
Copy Markdown
Contributor Author

I decided to go with the simple approach from #1054.

Just a note that I haven't added this function to the Merge.Strict modules, since I cannot think of a situation where we would also need to force the values.

@meooow25 meooow25 requested a review from treeowl March 22, 2026 02:29
@treeowl
Copy link
Copy Markdown
Contributor

treeowl commented Mar 22, 2026

This makes me pretty nervous. One of the major reasons I wrote the new merge interface was to get away from the earlier approach with pretty complex preconditions on user-passed arguments.

@meooow25
Copy link
Copy Markdown
Contributor Author

The motivation here is that it is actually useful to allow this, e.g. to calculate union and intersection at once (#944). An analogy might be lens allowing you define your own Lens, provided you satisfy the laws.

The alternative would be to tell people that they need to use the internal module to do what they want to do. The functionality is less discoverable and has less stability guarantees.

@treeowl
Copy link
Copy Markdown
Contributor

treeowl commented Mar 22, 2026

The representation of WhenMissing also has no stability guarantees. In fact, my original implementation sketch made it a GADT! That said, making such a guarantee probably wouldn't hurt too much. Let me take a look at your example uses. At the very least, I think the preconditions need to take on a sterner tone.

@meooow25
Copy link
Copy Markdown
Contributor Author

meooow25 commented Apr 5, 2026

@treeowl did you get a chance to look at the examples?

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.

Can we make the Map.Merge API more expressive?

2 participants