On Wed, Jul 17, 2013 at 11:17 AM, Alex Burr <[email protected]> wrote:
> Under instance coherence, only one implementation of a trait per type is > allowed. Haskell enforces this property at link time, because conflicting > implementations might only be discovered when separate compilation units > are linked. However, in Rust we're interested in forbidding conflicting > implementations sooner. > Consider a program consisting of four interlinked crates C1, C2, C3, and > C4, where C1 defines the trait C1Trait and C2 defines the type C2Type. > Under instance coherence, crate C3 would not be allowed to directly > define an impl of C2Type for C1Trait, because this leaves us open to the > possibility of crate C4 doing the same thing, resulting in conflicting > implementations. However, this is not a problem for expressivity, because > it is always possible for C3 to create a new nominal alias for C2Type and > then define an impl for *that* type. Alternatively, both the trait and > the impl could be defined in C1." > What an awful description. It says that X is not allowed, and it asserts that Y is enforced, but it never says *how* Y is enforced. Given a trait tr declared in crate C1, and a type typ declared in C2, where is it permitted to define an implementation of tr<typ>? That is: what rules concerning the definition of trait implementations ensure (allegedly) that implementations cannot collide? >From the discussion on the wiki page<https://github.com/mozilla/rust/wiki/Proposal-for-unifying-traits-and-interfaces>, I am not convinced that link safety is preserved. Or at least, I'm not convinced that it is possible to simultaneously have genericity and trait preservation. Does Rust support generic implementations of traits? But also, there's a fairly foundational problem in their mod C3 example, which I've described on the BitC list before. The problem arises because traits don't always have a single implementation. Consider that there are two orderings of natural numbers (by < and by >) and therefore two reasonable implementations of the Ord trait for natural numbers....
_______________________________________________ bitc-dev mailing list [email protected] http://www.coyotos.org/mailman/listinfo/bitc-dev
