Left-bias and non-structural equality.
Christian Maeder
maeder at tzi.de
Wed Jan 4 12:37:16 EST 2006
Arie Peterson wrote:
> It seems that there are two uses of Set e:
>
> 1) the Ord-comparison of e's is a total ordering / Eq e implements
> semantic equality;
>
> 2) Eq e is some equivalence relation, such as in Christian's example above.
This is more often the case than one might like. Even for the type Set
itself Eq/Ord can be observed differently by the debugging function
showTree.
> I agree with Jean-Philippe that 2) must not be advocated:
ok
> users should
> always use a Map instead (e.g. Map Symbol Position, with 'real equality'
> on Symbol).
if I have:
data Symbol = Symbol String Position
instance Eq/Ord Symbol -- compare String only
I'd rather like "Map Symbol Position" than "Map String Position" if I
want to be more explicit about positions.
> Now, it may save effort to *implement* Map by doing exactly 2), with e =
> MapElement a b. The work needed to reimplement Map would have to be
> compared to the work needed to ensure that Set supports use 2).
>
> However, this is purely a consideration of implementation, and does not
> effect the user experience of Set and Map - provided that she only uses
> Set as per 1).
Controlled bias is simply an additional benefit of the Data.Set library
implementation that you must not and are not encouraged to use (but that
may be helpful if you know what you are doing),
C.
More information about the Libraries
mailing list