Quantcast

ANN: signed-multiset-0.1

classic Classic list List threaded Threaded
30 messages Options
12
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

ANN: signed-multiset-0.1

Stefan Holdermans-2
I am pleased to announce the first release of signed-multiset, which implements an abstract datatype for multisets with negative membership.

The package can be obtained from

  http://hackage.haskell.org/package/signed-multiset-0.1

As always, feedback is welcome.

Cheers,

  Stefan


signed-multiset-0.1
-------------------

Multisets (or bags) are sets in which elements may occur more than once.
The number of times an element occurs in a multiset is called its
multiplicity.

This package provides an efficient implementation of so-called
signed multisets, which generalise multisets by allowing for
negative membership.
That is, elements in a signed multiset can have negative multiplicities.

See also: Wayne D. Blizard. Negative membership.
Notre Dame Journal of Formal Logic/, 31(3):346--368, 1990.
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Ivan Lazar Miljenovic
On 18 April 2012 14:26, Stefan Holdermans <[hidden email]> wrote:

> I am pleased to announce the first release of signed-multiset, which implements an abstract datatype for multisets with negative membership.
>
> The package can be obtained from
>
>  http://hackage.haskell.org/package/signed-multiset-0.1
>
> As always, feedback is welcome.
>
> Cheers,
>
>  Stefan
>
>
> signed-multiset-0.1
> -------------------
>
> Multisets (or bags) are sets in which elements may occur more than once.
> The number of times an element occurs in a multiset is called its
> multiplicity.
>
> This package provides an efficient implementation of so-called
> signed multisets, which generalise multisets by allowing for
> negative membership.
> That is, elements in a signed multiset can have negative multiplicities.

Wait, something can be not in the multiset more than once? :o

>
> See also: Wayne D. Blizard. Negative membership.
> Notre Dame Journal of Formal Logic/, 31(3):346--368, 1990.
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe



--
Ivan Lazar Miljenovic
[hidden email]
http://IvanMiljenovic.wordpress.com

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
Ivan,

>> This package provides an efficient implementation of so-called
>> signed multisets, which generalise multisets by allowing for
>> negative membership.
>> That is, elements in a signed multiset can have negative multiplicities.

> Wait, something can be not in the multiset more than once? :o

That's correct. :)

Cheers,

  Stefan

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Johannes Waldmann
In reply to this post by Stefan Holdermans-2
Stefan Holdermans <stefan <at> vectorfabrics.com> writes:

> This package provides an efficient implementation of so-called
> signed multisets, which generalise multisets by allowing for
> negative membership.

SignedMultiset a = Data.Map.Map a Integer

so what do I gain by using your library?
(what is the API difference?)

Perhaps you could state this clearly at the top
of the package description (visible on hackage).

I sometimes find I want a type "Map with default"
(the default value is stored when the Map is constructed,
and you never put keys in there that map to this default).

Best - J.W.



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
Johannes,

>> This package provides an efficient implementation of so-called
>> signed multisets, which generalise multisets by allowing for
>> negative membership.

> SignedMultiset a = Data.Map.Map a Integer

Indeed.

> so what do I gain by using your library?
> (what is the API difference?)

The library essentially provides some abstractions for recurring patterns when interpreting maps from elements to integers as signed multisets or free abelian groups: cardinality, union, additiveUnion, intersection, difference. Additionally it provides dedicated parsing and pretty printing utilities.

It's just like Data.Set provides abstractions from the patterns that arise when interpreting values of type Data.Map.Map a Bool (for an element type a) as sets.

> I sometimes find I want a type "Map with default"
> (the default value is stored when the Map is constructed,
> and you never put keys in there that map to this default).

You could think of SignedMultiset as an instantiation of that type (i.e., the one obtained by fixing the default to 0.

HTH,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
In reply to this post by Stefan Holdermans-2
Release early, release often. Here's a second version:

  http://hackage.haskell.org/package/signed-multiset-0.2

Changes:

* Added the functions Data.SignedMultiset.isPositive and
  Data.SignedMultiset.isNegative, which return whether all elements in a
  signed multiset have respectively nonnegative or nonpositive multiplicity.

* Added the functions Data.SignedMultiset.shadow, Data.SignedMultiset.modulus,
  Data.SignedMultiset.signum, and Data.SignedMultiset.unitstep which return
  respecitively the additive inverse, modulus, signum, and left-continuous unit
  step of a signed multiset.

* Added the functions Data.SignedMultiset.filter, Data.SignedMultiset.partition,
  and Data.SignedMultiset.split for filtering and partitioning signed
  multisets.

* Added the functions Data.SignedMultiset.foldr' and Data.SignedMultiset.foldl',
  which are strict versions of Data.SignedMultiset.foldr and
  Data.SignedMultiset.foldl.

* Changed the behaviour of both the function Data.SignedMultiset.fromList and
  the Read instance of Data.SignedMultiset: it multiple element/multiplicity
  pairs are provided for the same element, the multiplicity of the element in
  the constructed multiset is now taken to be the sum of the provided
  multiplicities (rather than the rightmost multiplicity).

* Added the functions Data.SignedMultiset.toLists and
  Data.SignedMultiset.fromLists, which convert between signed multisets and
  pairs of lists of elements with positive and negative multiplicity.

* Made the dependency on the base and containers packages more restrictive. The
  dependency for base now carries the version constraint == 4.5.*, while the
  dependency for containers now comes with the constraint >= 0.4.2 && < 0.5.

Cheers,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Jacques Carette
On 19/04/2012 4:10 AM, Stefan Holdermans wrote:
Release early, release often. Here's a second version:

  http://hackage.haskell.org/package/signed-multiset-0.2


Very cool.

In the literature, we have found [1] that these are sometimes also called 'hybrid sets'.  They do have some rather interesting applications, at least when paired up with an appropriate notion of partition (shameless plug warning).

Jacques

PS: the Haddock did not work for 0.2, but did for 0.1, you might want to look into that.

[1] http://dl.acm.org/citation.cfm?id=1894501
but also http://www.cas.mcmaster.ca/~carette/publications/calculemus10-final.pdf
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
Jacques,

> In the literature, we have found [1] that these are sometimes also called 'hybrid sets'.

They also go by the name of 'shadow sets', which also has a cool ring to it. ;)

> PS: the Haddock did not work for 0.2, but did for 0.1, you might want to look into that.

As I just uploaded the 0.2 version today, I don't think the documentation on Hackage was built yet. Locally, Haddock runs fine on it for me, but let me know if encounter any issues.

> [1] http://dl.acm.org/citation.cfm?id=1894501

> but also http://www.cas.mcmaster.ca/~carette/publications/calculemus10-final.pdf

Interesting! Added it to my reading list.

Cheers,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Richard A. O'Keefe
In reply to this post by Stefan Holdermans-2
Signed multisets are unfamiliar to most of us, and I for one
found the paper a little fast-paced.  Can you put a bit more
into the documentation?  Just for starters, I found it
confusing when the documentation talks about "an element with
multiplicity zero", because in the _paper_ a value that has
multiplicity zero in an mzset is NOT an element of it.

For a specific example, I haven't the faintest intuition about
what 'map' should do.  Suppose we have
        {(k1)x1, (k2)x2}
and f x1 == f x2 = y.  Should the value of map f {...} be
{(k1+k2)y} or {(k1`max`k2)y} or what?


I think anyone is going to be confused that a non-empty
mzset can have 'cardinality' 0, so a little more reassurance
that cardinality/=size is intentional might not go amiss.
Perhaps an additional name such as totalMultiplicity could
make things a little easier for writers and readers, even
though cardinality is correct.

Are you _sure_ that the definitions of isSubmultisetOf and
isProperSubmultisetOf are correct?  Proper sub<thing> is
normally taken as requiring that only *one* member of the
larger collection occur strictly fewer times in the smaller;
here you require that for *all*.

At least once, "multiplicities" is spelled "multiplicites".



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

wren ng thornton
On 4/19/12 7:02 PM, Richard O'Keefe wrote:
> For a specific example, I haven't the faintest intuition about
> what 'map' should do.  Suppose we have
> {(k1)x1, (k2)x2}
> and f x1 == f x2 = y.  Should the value of map f {...} be
> {(k1+k2)y} or {(k1`max`k2)y} or what?

Good question. I'd suppose that they should be parametrized by any
(Abelian?) group on the weights/multiplicities, where (+) is the
canonical one since we're talking about "negative" membership. Though
it'd be nice to get clarification, and to actually have the group/etc be
a parameter (i.e., by type class constraint) rather than hard-coded into
the structure.

--
Live well,
~wren

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
In reply to this post by Richard A. O'Keefe
Richard,

Thanks for your excellent feedback! Very helpful!

> Signed multisets are unfamiliar to most of us, and I for one found the paper a little fast-paced.  Can you put a bit more into the documentation?

Definitely. That's what weekends are for... :) I'll add some sections to the documentation that explain the main concepts and intuitions.

> Just for starters, I found it confusing when the documentation talks about "an element with multiplicity zero", because in the _paper_ a value that has multiplicity zero in an mzset is NOT an element of it.

I see... It seems that with multisets every value of the appropriate type is an element of the set, but some values (i.e., those with multiplicities > 0) are more of an element than others (i.e., those with multiplicity 0). In the paper this is reflected by having the "element-of" relation a ternary relation between elements, sets, and multiplicities (with a "functional dependency" from elements and sets to multiplicities). Confusingly, "not-an-element-of" notation is used as an abbreviation for "element-of with multiplicity zero".  

The library labels elements with multiplicities > 0 as "members".

> For a specific example, I haven't the faintest intuition about
> what 'map' should do.  Suppose we have
> {(k1)x1, (k2)x2}
> and f x1 == f x2 = y.  Should the value of map f {...} be
> {(k1+k2)y} or {(k1`max`k2)y} or what?

"Should" is a tricky term here. It depends on what you consider to be the structure of a multiset. Currently, map applies its function argument copywise:

  {x1_1,    x1_2,    ...,    x1_k1,    x2_1,   x2_2,    ...,   x2_k2  }
   |        |                |         |       |               |
   | f      | f              | f       | f     | f             | f
   v        v                v         v       v               v
  {y_1,     y_2,     ...,    y_k1,     y_k1+1, y_k1+2,  ...,   y_k1+k2}∑

That is, we preserve the additive structure.

But perhaps this is inconsistent: the Monoid instance for SignedMultiset operates on the extremal structure rather than the additive structure. A wrapper type Additive,

  newtype Additive a = Additive (SignedMultiset a)

supplies a monoid instance that operates on the additive structure. So, perhaps, it's better to have map as it is implemented now, operate on Additive rather than SignedMultiset and have a map for SignedMultiset that uses max rather than (+).

A rationale for this would be that, this way, map would be a proper generalisation of ordinary sets. (The same rationale has been applied to union.)

Pondering over this, I realise that the difference operator also doesn't property generalise the concept for ordinary sets. However, that concept indeed seems a bit more tricky to generalise.

> Are you _sure_ that the definitions of isSubmultisetOf and
> isProperSubmultisetOf are correct?  Proper sub<thing> is
> normally taken as requiring that only *one* member of the
> larger collection occur strictly fewer times in the smaller;
> here you require that for *all*.

You are right: isProperSubmultisetOf is too restrictive. I'll fix it.

Thanks,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
In reply to this post by wren ng thornton
Wren,

>> For a specific example, I haven't the faintest intuition about
>> what 'map' should do.  Suppose we have
>> {(k1)x1, (k2)x2}
>> and f x1 == f x2 = y.  Should the value of map f {...} be
>> {(k1+k2)y} or {(k1`max`k2)y} or what?
>
> Good question. I'd suppose that they should be parametrized by any (Abelian?) group on the weights/multiplicities, where (+) is the canonical one since we're talking about "negative" membership.

Any groupoid on the multiplicities would do, I guess.

As I wrote in my answer to Richard, max seems a better choise, as it nicely generalises mapping on sets.

Cheers,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Sjoerd Visscher-2
I don't think max would be a good choice, as that would mean that the default multiplicity would have to be negative infinity (the identity element of max) instead of 0, and then using Int as the type for multiplicity would not cut it.

greetings,

Sjoerd

On Apr 20, 2012, at 11:02 AM, Stefan Holdermans wrote:

> Wren,
>
>>> For a specific example, I haven't the faintest intuition about
>>> what 'map' should do.  Suppose we have
>>> {(k1)x1, (k2)x2}
>>> and f x1 == f x2 = y.  Should the value of map f {...} be
>>> {(k1+k2)y} or {(k1`max`k2)y} or what?
>>
>> Good question. I'd suppose that they should be parametrized by any (Abelian?) group on the weights/multiplicities, where (+) is the canonical one since we're talking about "negative" membership.
>
> Any groupoid on the multiplicities would do, I guess.
>
> As I wrote in my answer to Richard, max seems a better choise, as it nicely generalises mapping on sets.
>
> Cheers,
>
>  Stefan
> _______________________________________________
> Haskell-Cafe mailing list
> [hidden email]
> http://www.haskell.org/mailman/listinfo/haskell-cafe
>

--
Sjoerd Visscher
[hidden email]




_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
Sjoerd,

>>>> For a specific example, I haven't the faintest intuition about
>>>> what 'map' should do.  Suppose we have
>>>> {(k1)x1, (k2)x2}
>>>> and f x1 == f x2 = y.  Should the value of map f {...} be
>>>> {(k1+k2)y} or {(k1`max`k2)y} or what?

> I don't think max would be a good choice, as that would mean that the default multiplicity would have to be negative infinity (the identity element of max) instead of 0, and then using Int as the type for multiplicity would not cut it.

Why would one need such an identity element for map?

Note that the monoidal structure isn't defined over the "maximum of multiplicites" but over the "maximum of *nonzero* multiplicites". (For ordinary sets and ordinary multisets these operations happen to coincide.)

Cheers,

  Stefan

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Sjoerd Visscher-2
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. You'll have to call norm everywhere to make it work, f.e. you would expect this to work:

empty' = insert () $ delete () empty

but:

empty' <> delete () empty == empty'

while:

empty <> delete () empty == delete () empty

(I couldn't test it as I don't have base 4.5, so I hope I didn't make a mistake here.)

greetings,
Sjoerd

On Apr 23, 2012, at 2:07 PM, Stefan Holdermans wrote:

> Sjoerd,
>
>>>>> For a specific example, I haven't the faintest intuition about
>>>>> what 'map' should do.  Suppose we have
>>>>> {(k1)x1, (k2)x2}
>>>>> and f x1 == f x2 = y.  Should the value of map f {...} be
>>>>> {(k1+k2)y} or {(k1`max`k2)y} or what?
>
>> I don't think max would be a good choice, as that would mean that the default multiplicity would have to be negative infinity (the identity element of max) instead of 0, and then using Int as the type for multiplicity would not cut it.
>
> Why would one need such an identity element for map?
>
> Note that the monoidal structure isn't defined over the "maximum of multiplicites" but over the "maximum of *nonzero* multiplicites". (For ordinary sets and ordinary multisets these operations happen to coincide.)
>
> Cheers,
>
>  Stefan
>





_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
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.

> empty' = insert () $ delete () empty
>
> but:
>
> empty' <> delete () empty == empty'
>
> while:
>
> empty <> delete () empty == delete () empty
>
> (I couldn't test it as I don't have base 4.5, so I hope I didn't make a mistake here.)

*Data.SignedMultiset> let empty' = insert () $ delete () empty

*Data.SignedMultiset> empty' `union` delete () empty == empty'
False

*Data.SignedMultiset> empty `union` delete () empty == delete () empty
True

Cheers,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Sjoerd Visscher-2

On Apr 23, 2012, at 3:18 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?

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


Ah, I missed the check in insertMany.

What about the same with

let empty' = multiply 0 $ delete () empty

greetings,
Sjoerd



_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
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.

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

> Ah, I missed the check in insertMany.
>
> What about the same with
>
> let empty' = multiply 0 $ delete () empty

*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

Cheers,

  Stefan
_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Sjoerd Visscher-2

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

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
Reply | Threaded
Open this post in threaded view
|  
Report Content as Inappropriate
star

Re: ANN: signed-multiset-0.1

Stefan Holdermans-2
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

_______________________________________________
Haskell-Cafe mailing list
[hidden email]
http://www.haskell.org/mailman/listinfo/haskell-cafe
12
Loading...