-
Notifications
You must be signed in to change notification settings - Fork 154
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
Added subtypes for Inference #464
base: master
Are you sure you want to change the base?
Conversation
Fixes fthomas#454 Here I've tried to have Inference as a trait and added 2 subtypes - InferAlways - InferWhen With that we can directly have a safe conversion whenever an InferAlways is presen
It is failing cause I added subtypes for @fthomas I would appreciate some feedback on the approach I took, and whether you'd like to see some changes or It doesn't make sense at all the pull request. |
* This trait is used to implement refinement subtyping. | ||
*/ | ||
trait Inference[P, C] { | ||
type T[P2, C2] <: Inference[P2, C2] |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What is the purpose of T
? I see that it is used in adapt
but can't we just use Inference
there? Subtypes should be able to override adapt
with a more concrete type (eg. override def adapt[P2, C2](adaptedShow: String): InferAlways[P2, C2] = ...
).
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I kept it there in case we wanted to use Dependent types for something like; def something[C,P](f: Inference[C,P]): f.T[C,P] = f...
However in the end I didn't find a way to use it for the implicit conversion. So if that's unnecessary any longer I can do it as suggested
The implicit def modusTollens[A, B](implicit p1: Inference[A, B]): p1.T[Not[B], Not[A]] =
p1.adapt("modusTollens(%s)") ? |
Forget that, my last suggestion does not work for implicit def hypotheticalSyllogismAlways[A, B, C](implicit p1: A ==> B, p2: B ==> C): A ==> C =
Inference.combine(p1, p2, "hypotheticalSyllogism(%s, %s)") |
Yes your suggestion is exactly what I was trying to achieve by adding the T abstract type however I also realized it doesn't work for all cases |
I've thought about this a bit more and I think I made a mistake in the design of |
The more I think about this issue, the more I become convinced that we should remove
Arguments against removing that field:
|
I agree. It became also clear to me when attempting to fix this issue that it would be better to have Inference as always valid and consequently macro would not be needed. It seems feasible to do, having the disadvantage of breaking binary compatibility |
Ok, let's do this. I hope that instances for |
Fixes #454
Here I've tried to have Inference as a trait and added 2 subtypes
With that we can directly have a safe conversion whenever an InferAlways is presen