[Haskell-cafe] ANN: signed-multiset-0.1

Sjoerd Visscher sjoerd at w3future.com
Mon Apr 23 16:52:40 CEST 2012


On Apr 23, 2012, at 4:34 PM, Stefan Holdermans wrote:

> Sjoerd,
> 
>>>> This is not just about map, but it also a problem for the Monoid instance. You are basically adding an extra identity element, 0, to the max monoid, which works but is weird.
> 
>>> Still that's how union is typically defined for hybrid sets. It's what happens if want union and empty to behave as generalisations of these concepts for ordinary (multi)sets.
> 
>> Then why would you want that?
> 
> You don't have to. (SignedMultiset a, additiveUnion, empty) gives you the Monoid that you seem to have a preference for. The library supplies it through the Additive wrapper. The point is that you have a choice: different applications may ask for different monoidal structures.

Agreed. But I just can't imagine that the other instance is in any way useful. You basically define a function max':

max' :: Int -> Int -> Int
max' 0 b = b
max' a 0 = a
max' a b = max a b

i.e.

max' -2 -1 = -1 
max' -2 0 = -2
max' -2 1 = 1

Wouldn't you agree that if you saw this defined in some code, you'd think something is wrong?

> *Data.SignedMultiset> let empty' = multiply 0 $ delete () empty
> 
> *Data.SignedMultiset> empty' `union` delete () empty == empty'
> True
> 
> *Data.SignedMultiset> empty `union` delete () empty == delete () empty
> True


And this doesn't bother you?

greetings,
Sjoerd



More information about the Haskell-Cafe mailing list