ketil+haskell at ii.uib.no
Tue Mar 16 15:44:19 EST 2004
JP Bernardy <jyp_7 at yahoo.com> writes:
>> Would this make sense? Would it be useful?
> I'm not sure that I understand either :)
Yeah, my definitions weren't exactly clear. I'll try to elucidate:
> Let me give an example...
>> type MyString = MyString String
>> instance Eq MyString where
>> (MyString x) == (MyString y) = length x == length y
I'm sure you'll agree that this is not something anybody sane would
do. (Actually, I did something remotely similar, and I've regretted
it ever since; it gave me some nasty, hard-to-track down bugs. I
always derive Eq since then.)
Which is why I think Bag perhaps should, instead of relying on Eq (or
actually Ord, I suppose), be provided with a separate parameter
specifying how to compare items for equality for bagging purposes.
>> Bag.toString $ Bag.fromString $ [ms "x", ms "y"]
So instead of doing this, I would like to be able to do
mkBag myComp [ms "x", ms "y"]
where myComp x y = compare (length x) (length y)
which would then bag all equal-length strings (possibly storing them
in multisets using regular Eq).
> That is why I choose to keep the "MultiSet" name.
Just to make that clear, I've no issue with the naming.
> If Eq is defined as structural equality, MultiSet and
> Bag are equivalent.
And since Eq "should" define structural equality, I propose a
different interface for Bags (if we need them at all, that is)
Was that a bit clearer?
If I haven't seen further, it is by standing in the footprints of giants
More information about the Libraries