Ixrec / rust-orphan-rules

An unofficial, experimental place for documenting and gathering feedback on the design problems around Rust's orphan rules
Apache License 2.0
200 stars 3 forks source link

Are newtypes always an option? #5

Open Ixrec opened 6 years ago

Ixrec commented 6 years ago

As far as I know, any time you run into an orphan rules violation, it is always possible to solve it by writing a newtype. It might be tedious to write, or not the ideal solution, but I'm not aware of a case that's impossible to solve with a newtype.

This issue is for proving me wrong.

FrankHB commented 7 months ago

NO.

I don't want to detail too mach, but there should be the simple case: for a type W<A> where W is a library generic type depending on client (user-provided) type A for function right, it may be not appropriate to introduce any new types for either W, A, or W<A> because the remaining program relies on their type identity.

For example, sane language binding implementation distinguish strictly about any "newtype" and wrapped type as different ones, for clear logical reasons. A is not new type for A. W<A> is not new type for W<A>. This should be true in any nominal type systems, including Rust; and an object language will assume this, too. Then, where should W<A> be settled down?

New types cannot be introduced to resolve the problem because: