Idea for 0 and negative values.#10
Conversation
|
I'm not sure what the meaning of multiset with 0 or negative occurrences is. This change would make a break with the mathematical concept of multiset (https://en.wikipedia.org/wiki/Multiset) where the multiplicity is constrained to 1 or more. If I wanted to track zero or negative values associated with a key, I would probably use |
|
I see, well, that's true, it would not be a multiset in the mathematical sense (I think it could be modeled as a free abelian group https://en.wikipedia.org/wiki/Free_abelian_group). About 0 occurrences, it already handles them consistently everywhere but on About the negatives values, the thing is, there are people using Multiset to count, so having negative number is quiet useful, but annoying to re-implement Map every time for every project. Actually it could be nice generalize it to anything with an But its true it change the behavior, maybe could it be an Idea to move it to another module within the package and give it another name instead of |
|
If it were to have a name other than |
|
Looks like something like this already exists: https://hackage.haskell.org/package/signed-multiset. They're using the name "signed multiset". |
|
I was not aware of that package, which even has a similar interface! Now I'm not longer sure if it would be a good idea to duplicate that module; What do you think? On one side duplication is not nice, but on the other they have some functions that are similar but not the same, what can lead to errors, for instance, what there's If you think it is a good idea to have |
|
Apart from that, there's still the question what to do with zero and negative values when they appeared on |
|
I agree that For compatibility with the signed-multiset package, perhaps it makes sense to add |
|
I set it back to behave as it used, just adding a |
I case you think it is ok handling 0 or negative occurrences, here it is pull request with a possible implementation. I had some doubts though:
sizereturn the amount of positive occurrences? or any occurrences different than 0?memberreturnTrueif the occurrence is negative or only when it is positive?intersectionis intuitive?