-
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
Macro expansion error with generic Inference #454
Comments
That's interesting! I've never worked with an explicit Unfortunately the instance scala> implicitly[Greater[_5] ==> Greater[_10]]
res1: Greater[_5] ==> Greater[_10] = Inference(false,greaterInferenceNat(5, 10)) Which shows that we can find an I think what is missing to define your def infer(tp: F[T, B])(implicit rt: RefType[F], I: B ==> A): Option[F[T, A]] =
if (I.isValid) Some(rt.unsafeRewrap[T, B, A](tp)) else None With def convert[B, A](value: String)(implicit I: B ==> A,
V: Validate[String,B]): Either[String, String Refined A] = {
val res = applyRef[String Refined B](value)
res.flatMap(v => infer(v).fold(Left("B does not implies A"))(Right.apply) )
} |
Thanks. That is useful. You are right, an It would be cool to have a subtype of Inference which is always valid ( Something like that: sealed trait Inference {
def isValid: Boolean
def show: String
}
object Inference {
object ValidAlways extends Inference {
def isValid: Boolean = true
}
object ValidNever extends Inference {
def isValid: Boolean = false
}
final case class ValidWhen(isValid: Boolean) extends Inference
}
|
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
I have the following generic method to convert from
String
toString Refined A
.However, this is somewhat different because I'm going to try to convert String to
String Refined B
and then infer A from B, as follows:I need a
Validate[String,B]
to convert from String toString Refined B
and I need aInference[B,A]
to convert fromString Refined B
toString Refined A
. So far so good.But this code does not compile. This is the stacktrace:
The text was updated successfully, but these errors were encountered: