On Sun, 24 May 2009, Ketil Malde wrote:

Duncan Coutts <duncan.cou...@worc.ox.ac.uk> writes:

The PVP says:

             1. If any entity was removed, or the types of any entities
                or the definitions of datatypes or classes were changed,
                or instances were added or removed, then the new A.B
                must be greater than the previous A.B.

When I read this point the first time, I was fine with this convention. But the more hassle I had with orphan instances I came to the conclusion that they are bad enough that they should be treated like unqualified anonymous imports. I mean, version policy warrants that I can import a module of any package version of type A.B.* when I use exclusively qualified imports or explicit unqualified imports. Instances are always imported whenever you touch a module, you cannot exclude them. Thus they behave like anonymous imports - you cannot control what exactly is imported. Version policy does not support anonymous unqualified imports because it does not make any warranties if you import this way.

What about orphan instances? If a module misses an instance that belongs to one of its types or its classes then it may be added by any other module in any other package. If that is done then those orphan instances are likely to clash sooner or later. The version policy should warrant that within the A.B.* version range I'm safe to import a module the qualified or explicitly unqualified way. But since orphan instances can get in the way, we don't have this warranty! Say I import packages foo-1.2.3 and bar-4.5.6, where foo exports orphan instance C T and bar does not import such an instance. I see that it works and think this will continue to work as long as I restrict to foo >=1.2.3 && <1.3 and bar >= 4.5.6 && <4.6. Now, the new version bar-4.5.7 starts to import package hmpf-8.9.0, which provides another orphan instance C T. It is allowed to depend on new packages in such a version bump, right? Now, my package can no longer be compiled, because 'bar' re-exports the orphan instance from 'hmpf'.

My proposal is thus: Discourage orphan instances! If you encounter that an instance is missing and it is a canonical one, it should be added to the package that defines the type or the class. If there are several choices for the implementation then the package where the instance would belong to should document that. Then programmers should find a consensus which of the choices they prefer. If you cannot wait for an official adaption of the required instance, then you must work with newtype wrappers.

There are cases where you must define an orphan instance. Then this should instance should go into a new package by consensus between the maintainer of the class and the maintainer of the type.

However, when orphan instances are banned, then it would also be no problem to add instances to their home modules within the A.B.* range. So I vote for allowing this, too.
_______________________________________________
Haskell-Cafe mailing list
Haskell-Cafe@haskell.org
http://www.haskell.org/mailman/listinfo/haskell-cafe

Reply via email to