relax orphan rule for `(define-instance (A:A :x => B:B :x) ...)`
stylewarning opened this issue · comments
The orphan rule seems overly restrictive for what I imagine is a somewhat common case of defining a new class, and implementing instances implied by that class. Specifically, if A:A
(package A
with class A
) is defined and we wish to define an instance of B:B
, like so:
(define-instance (A:A :t => B:B :t) ...)
then we need to define this in the package B
. This is inconvenient, because it means that we would need to put A:A
very early in our project, divorcing it from additional logic/library functionality.
I propose we just add this as a special case to the orphan rule. I don't think we need to generalize it (e.g., (A1:A1 :t) (A2:A2 :t) => B:B :t)
or anything like that), but it might be worth it.
Any downsides to doing this?
CC @macrologist
One minor minus that comes to mind is that this would lead to a degree of arbitrariness in the decision about where to put multiply-constrained typeclass instances.
(define-instance ((A:A :t) (B:B :t) => C:C :t) ...)
where, by convention, do we put this? A.lisp
or B.lisp
?
Others?
where, by convention, do we put this?
A.lisp
orB.lisp
?
(FWIW, I would think it's usually the case that one of these is the load-bearing one.)