Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

relax orphan rule for (define-instance (A:A :x => B:B :x) ...) #1010

Open
stylewarning opened this issue Oct 6, 2023 · 3 comments
Open

relax orphan rule for (define-instance (A:A :x => B:B :x) ...) #1010

stylewarning opened this issue Oct 6, 2023 · 3 comments

Comments

@stylewarning
Copy link
Member

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?

@stylewarning
Copy link
Member Author

CC @macrologist

@macrologist
Copy link
Collaborator

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?

@stylewarning
Copy link
Member Author

where, by convention, do we put this? A.lisp or B.lisp ?

(FWIW, I would think it's usually the case that one of these is the load-bearing one.)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants