Avoiding the hazards of orphan instances without dependency problems

David Feuer david.feuer at gmail.com
Sun Oct 19 17:02:35 UTC 2014


Orphan instances are bad. The standard approach to avoiding the orphan
hazard is to always put an instance declaration in the module that declares
the type or the one that declares the class. Unfortunately, this forces
packages like lens to have an ungodly number of dependencies. Yesterday, I
had a simple germ of an idea for solving this (fairly narrow) problem, at
least in some cases: allow a programmer to declare where an instance
declaration must be. I have no sense of sane syntax, but the rough idea is:

{-# InstanceIn NamedModule [Context =>] C1 T1 [T2 ...] #-}

This pragma would appear in a module declaring a class or type. The named
module would not have to be available, either now or ever, but attempting
to declare such an instance in any module *other* than the named one would
be an error by default, with a flag
-XAllowForbiddenInstancesAndInviteNasalDemons to turn it off. The optional
context allows multiple such pragmas to appear in the type/class-declaring
modules, to allow overlapping instances (all of them declared in advance).
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.haskell.org/pipermail/ghc-devs/attachments/20141019/427cee56/attachment.html>


More information about the ghc-devs mailing list