[Haskell-cafe] ANN: signed-multiset-0.1
Stefan Holdermans
stefan at vectorfabrics.com
Mon Apr 23 19:04:36 CEST 2012
Sjoerd,
>>> 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?
If max' is supposed to implement the maximum of two nonzero values, I wouldn't be the slightest bit concerned. Seriously: if this is what people have agreed on to be a sensible semantics for hybrid sets, I am fine implementing it like this.
>> *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?
Of course it does; it pinpoints a bug in multiply. It's fixed now:
*Data.SignedMultiset> let empty' = multiply 0 $ delete () empty
*Data.SignedMultiset> empty' `union` delete () empty == empty'
False
*Data.SignedMultiset> empty `union` delete () empty == delete () empty
True
Cheers,
Stefan
More information about the Haskell-Cafe
mailing list