Skip to content

Coherent type classes #2046

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

Closed
wants to merge 2 commits into from
Closed

Conversation

odersky
Copy link
Contributor

@odersky odersky commented Mar 2, 2017

A simple implementation of a Coherent trait which avoids
ambiguity errors for goals that derive from it.

It implements #2047.

A simple implementation of a Coherent trait which avoids
ambiguity errors for goals that derive from it.
@retronym
Copy link
Member

retronym commented Mar 3, 2017

A variation on this theme might be to allow ambiguity if all the candidates extends Coherent, even if the implicit search itself doesn't. That would allow code requiring typeclasses to be more general (it doesn't have to limit itself to implicitly accepting coherent instances).

I can also imagine it might be necessary from time to time to cast an incoherent instance to a coherent one. Having Coherent as a marker interface might make this impossible. With some boilerplate you could achieve the same through a delegating wrapper instance, I guess. Or we could find a way to make the coherent marker type completely erase away to allow casting.

@odersky
Copy link
Contributor Author

odersky commented Mar 3, 2017

A variation on this theme might be to allow ambiguity if all the candidates extends Coherent, even if the implicit search itself doesn't. That would allow code requiring typeclasses to be more general (it doesn't have to limit itself to implicitly accepting coherent instances).

I think that's closer in spirit to @djspiewak's proposal https://gist.github.com/djspiewak/9f6feadab02b16829c41484b394d16e4. But applied to the present proposal #2047 it would not work, because the alternatives might come from different coherence domains. I.e. the fact that they all implement a coherent type does not guarantee that they agree on the implementation of the expected type.

@odersky
Copy link
Contributor Author

odersky commented Mar 3, 2017

@retronym Regarding casting: It's of course always good to have an escape hatch. But in the case of implicit resolution we already have one: Just pass parameters explicitly. So, do you think we need more than that?

I like the formulation of Coherent as a marker trait because that neatly captures the rule that all subtypes of a coherent type must themselves be coherent.

@puffnfresh
Copy link

I like it.

Could this be an annotation rather than a trait? This would be consistent with things like scala.annotation.implicitNotFound and scala.annoation.implicitAmbiguous.

Can we call it something like "implicitIgnoreAmbiguous" instead of Coherent? Coherency implies a lot more than what this functionality provides.

@odersky
Copy link
Contributor Author

odersky commented Apr 4, 2017

I am closing this for now, since we agreed we wanted to get coherency checking in first.

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

Successfully merging this pull request may close these issues.

3 participants