<p dir="ltr">I don't think your approach is flexible enough to accomplish the purpose. For example, it does almost nothing to help lens. Even my approach should, arguably, be extended transitively, allowing the named module to delegate that authority, but such an extension could easily be put off till later.</p>
<div class="gmail_quote">On Oct 19, 2014 7:17 PM, "John Lato" <<a href="mailto:jwlato@gmail.com">jwlato@gmail.com</a>> wrote:<br type="attribution"><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><div dir="ltr">Thinking about this, I came to a slightly different scheme.  What if we instead add a pragma:<div><br></div><div>{-# OrphanModule ClassName ModuleName #-}</div><div><br></div><div>and furthermore require that, if OrphanModule is specified, all instances can *only* appear in the module where the class is defined, the involved types are defined, or the given OrphanModule?  We would also need to add support for the compiler to understand that multiple modules may appear under the same name, which might be a bit tricky to implement, but I think it's feasible (perhaps in a restricted manner).</div><div><br></div><div>I think I'd prefer this when implementing orphan instances, and probably when writing the pragmas as well.</div></div><div class="gmail_extra"><br><div class="gmail_quote">On Mon, Oct 20, 2014 at 1:02 AM, David Feuer <span dir="ltr"><<a href="mailto:david.feuer@gmail.com" target="_blank">david.feuer@gmail.com</a>></span> wrote:<br><blockquote class="gmail_quote" style="margin:0 0 0 .8ex;border-left:1px #ccc solid;padding-left:1ex"><p dir="ltr">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:</p>
<p dir="ltr">{-# InstanceIn NamedModule [Context =>] C1 T1 [T2 ...] #-}</p>
<p dir="ltr">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).</p>
<br>_______________________________________________<br>
ghc-devs mailing list<br>
<a href="mailto:ghc-devs@haskell.org" target="_blank">ghc-devs@haskell.org</a><br>
<a href="http://www.haskell.org/mailman/listinfo/ghc-devs" target="_blank">http://www.haskell.org/mailman/listinfo/ghc-devs</a><br>
<br></blockquote></div><br></div>
</blockquote></div>