2009/5/19 Tony Morris <
tonymorris@...>:
> David MacIver wrote:
>> trait Hasher[-T]{
>> def hashOf(x : T) : Int;
>> def areEqual(x : T, y : T) : Boolean;
>> }
>>
>> this is then used to define the hashing behaviour of the collection,
>> much like Ordering. However there would be an implicit Hasher[Any]
>> available, so it would always succeed, but could specialise in some
>> cases.
>>
>>
> Unfortunately, if you supply an implicit Hasher for a more specific type
> than Any, it will not be selected over the one for Any. This is because
> Hasher is a contra-variant type constructor. This is from the top of my
> head, since I ran into this recently.
Hm. You seem to be correct. That's annoying.
This can be worked around by making the implicit Hasher for Any actually an
implicit def hasherForAny[T] : Hasher[T] = ...
but still, irritating!