« Return to Thread: Some 2.8 collection ideas that arose out of IRC discussion about hash codes

Re: Some 2.8 collection ideas that arose out of IRC discussion about hash codes

by Tony Morris-4 :: Rate this Message:

Reply to Author | View in Thread

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.

--
Tony Morris
http://tmorris.net/


 « Return to Thread: Some 2.8 collection ideas that arose out of IRC discussion about hash codes