Even though on the docs it says it should work only with positive values, sometimes it is easy missed introducing a hard to find bug (at least It happened to me :/ ). As an example, this can be unintuitive fromListOccur [(x,1),(x,-1)] == fromListOccur [(x,0)] /= fromListOccur [] . I think it might be a good idea either:
- Detect when a zero or negative has been used and throw an
error "negative or zero occurrences not supported".
- Extend the implementation such it handle zero and negative values. (Internally only storing elements with an occurrence different than 0 ).
I think the second option is more interesting cause it eliminates the problem and makes the library useful for new use-cases; but it would slightly change the current semantics of some functions.
Even though on the docs it says it should work only with positive values, sometimes it is easy missed introducing a hard to find bug (at least It happened to me :/ ). As an example, this can be unintuitive
fromListOccur [(x,1),(x,-1)] == fromListOccur [(x,0)] /= fromListOccur []. I think it might be a good idea either:error "negative or zero occurrences not supported".I think the second option is more interesting cause it eliminates the problem and makes the library useful for new use-cases; but it would slightly change the current semantics of some functions.