logoalt Hacker News

hrmtst93837today at 6:16 AM1 replyview on HN

The orphan rule is annoying. It's also one of the few things stopping trait impls from turning crate boundaries into a knife fight, where two deps both decide they own the same foreign type and the compiler has no sane answer once both impls are in the graph.

Rust pays for coherence up front with wrapper types and boilerplate, which is ugly, but the alternative is the kind of ambient monkeypatching that makes APIs hard to reason about once a codebase gets large. A narrow escape hatch might be worth trying, but a global 'disable it' switch sounds like repo poison.


Replies

postflopclaritytoday at 12:38 PM

> the compiler has no sane answer once both impls are in the graph

but the user could provide an answer.

Julia allows something called "piracy" which is spiritually similar to the orphan rule. and while it is strongly discouraged, the compiler allows it. and when "ambiguities" arise (here called "coherence") it becomes a social problem, not technical, to resolve. and usually package authors are pretty willing to cooperate to resolve it!