[rust-dev] "Instance Chains: Type Class Programming Without Overlapping Instances" and type classes in Rust

Patrick Walton pwalton at mozilla.com
Mon Jan 9 17:53:47 PST 2012


On 1/9/12 5:36 PM, Tim Chevalier wrote:
> The problem the paper addresses is in Haskell, where having multiple
> instances in scope for the same class and type can cause unpredictable
> behavior. (The paper explains the basic problem in more detail pretty
> well.) It seems like there's an analogous issue in Rust when you
> import multiple sets of methods for the same type class, which I
> understand is handled with a compile failure.

Our discussion led to the ability to disambiguate at the call site. 
However, it's not entirely satisfactory: it does mean that there are 
some subtle traps involving things you would like to be typeclasses 
(like Hashable) and consistency of data types (like what happens if you 
create a hash table and add some keys using one type class instance for 
Hashable and later on try to add keys using another type class instance 
for it).

Patrick


More information about the Rust-dev mailing list