Orphan Instances
Simon Peyton-Jones
simonpj at microsoft.com
Tue Aug 12 03:20:27 EDT 2008
| Ashley:
| What is an orphan instance, and why do we care about them?
They are documented in the GHC manual
http://www.haskell.org/ghc/docs/latest/html/users_guide/separate-compilation.html#orphan-modules
| Wolfram:
| I just would like to point out that there is nothing inherently bad about
| what GHC calls ``orphan instances''. ... that there is no *implementation-independent*
| reason to avoid ``orphan instances''.
|
| From a code structuring point of view,
| I frequently ``consider orphan'' instances
| useful for separation of concerns.
I agree. The warning just warns you that compilation of any module that depends on this module, or on the package of which this module becomes a part, will become a little slower, for reasons explained above.
| (On the implementation side, a completely different solution would be
| to add (automatically) re-exported instances (and rewrite rules)
| to the export lists stored inside .hi files ---
| then ``orphan instances'' would be no worse than other instances.)
Indeed, you could certainly accumulate in every M.hi file a list of all orphan instances anywhere below M. What GHC does instead is to accumulate a list of all the *modules that contain* orphan instances, which amounts to much the same thing. Either way it's tiresome because all these instances must be brought into scope for every compilation, even though most of them are useless.
As you say, though, it's just an implementation matter. That's why it's only a warning.
Simon
More information about the Libraries
mailing list