-
Notifications
You must be signed in to change notification settings - Fork 180
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
Use generic map merging framework #937
Comments
Yes, I found @jcranch's write up excellent and I'd recommend it to the |
Thanks for the write up. I do agree that this is a good way to define map merging, for two reasons as I see it:
But I also see some hurdles in the way of adopting this in containers:
|
This is my first foray into anything more central to the Haskell ecosystem than writing libraries. As a result, I think I'm ill-equipped to comment on the first and third of your hurdles, which seem to me to be dependent mostly on strategic priorities. I genuinely do not know what types of upheaval the relevant maintainers are willing to tolerate over any given timeframe. I'd be pleased to see experienced people state their opinions. The second of your hurdles is, however, within my competence. Set is not defined, but could be defined as
I have always calmly assumed that the containers people know what they're doing, and had solid performance reasons justifying a bespoke implementation rather than just implementing most of The value of this observation is that it gives you a way of specialising desirable functionality from maps to sets: any time you have an interesting function involving
There are also of course the specialisations (presumably The profusion of units in the type signatures are unpleasant, but the same merge tactics that work for map merges will work here, and will mean that the use cases which should be pleasant and idiomatic will indeed be pleasant and idiomatic. For example, we will have
Actually implementing these functions for |
@jcranch, while we could, theoretically, define |
Yes, and it would be even worse for IntSet because we would lose the packed Tips. We will have to accommodate sets and maps being distinct types. |
Don't worry (@treeowl and @meooow25), I'm not suggesting we do this, merely observing that the isomorphism between Approach 1I've implemented these functions, albeit in a slightly hackish way. The need for some amount of hackery is motivated by the issue (which might have been what @meooow25 was driving at last week) is that One can introduce a variant of
and there is no value of It is the case that no standard Approach 2The only safe alternative I can think of is to
I'm happy to do this if someone wants to see it. It won't take long. |
It is possible to make the code for merge tactics generic (so it can be used for Map and IntMap without duplication, and could also be used for other map-like data structures in other libraries), and to increase the safety in doing so.
I have created a repository containing both an implementation and a fairly lengthy explanation of how it works.
There are some decisions to be made about how to do it: most noticeably, there is a dependency upon Kinoshita's witherable library. I have demonstrated that this library can be trimmed down heavily, but there are still several possibilities for where it should go: it could go into base, into containers, or remain as a separate library (which would then need to be a dependency of containers).
@tomjaguarpaw has spent some time reviewing these ideas (I'm grateful for feedback on an earlier version); he may be willing to make his thoughts known.
The text was updated successfully, but these errors were encountered: