I want to get some feedback on Two equal priority queues with keys can compare as unequal · Issue #78 · lspitzner/pqueue · GitHub. MinPQueue k a
is a priority queue where the elements are basically pairs of a priority k
and a value a
(and that supports extraction of the minimum element).
The current Eq
instance checks if two pqueues produce the same elements when repeatedly extracting the minimum element, so two pqueues that produce the same elements, but in a different order, are considered to be not equal. Using this instance, insert
does not respect equality, i.e. insert
ing the same element into two equal pqueues may produce pqueues that are not equal.
Another option is to consider two pqueues to be equal if they have the same elements regardless of the order. Doing this in a naive way is really slow though. A faster way is to convert the pqueues to lists (by repeatedly extracting the minimum element), sort them and then compare them. This however would require an additional Ord a
constraint (before, there were only Ord k
and Eq a
constraints). This instance also has the problem that insert
doesn’t respect equality. Additionally, not even extracting the minimum preserves equality.
A third option is to just consider structural equality, but I think that wouldn’t be very useful.
Another, more radical option would be to simply remove the Eq
instance, for it being not obvious what the behaviour should be.
Which option would you expect and why?