-
Notifications
You must be signed in to change notification settings - Fork 21
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
implement higher-order unification for type constructor inference #2712
Comments
Imported From: https://issues.scala-lang.org/browse/SI-2712?orig=1 |
Harrison Klaperman (hlklaperman) said: |
@Blaisorblade said: |
@milessabin said: // Template we will unpack into
trait UnpackM[MA] {
type M[_]
type A
}
// Destructuring implicits
implicit def unpackM1[M0[_], A0] = new UnpackM[M0[A0]] {
type M[X] = M0[X]
type A = A0
}
implicit def unpackM2[M0[_, _], A0, B0] = new UnpackM[M0[A0, B0]] {
type M[X] = M0[A0, X]
type A = B0
}
def meh[MA](x : MA)(implicit u : UnpackM[MA]) : (u.M[String], List[u.A]) = null
// ^^ ^^^^^^^^^^^^^^^^^^^^^^^^ ^^^^^^^^^^^ ^^^
// (1) (2) (3) (3)
// 1: Type variable being destructured
// 2: Destructuring implicit
// 3: Uses of (dependent) component types
val m = meh{(x: Int) => x}
implicitly[m.type <:< (Int => String, List[Int])] See also here for a slightly more elaborate scalaz inspired example. |
@Blaisorblade said: type EitherInt[A] = Either[Int, A] Moreover, your code does not even correctly solve the original problem - it only infers that Int => Int matches M0[A0, B0] with M0 = Function1, not that it matches M1[A1] with M1[X] = X => X. |
@pchiusano said: Here's an example: case class State[S,A](run: S => (A,S))
object Blah {
def foo[M[_],A](m: M[A]): M[A] = m
...
val blah = foo(State((i: Int) => ("hi",i+1)))
} Another way to think about this is that type constructors are curried, so State[S,A] is actually represented as Ap(Ap(State, S), A), and likewise the M[A] is Ap(freevar, A) - these unify with freevar = Ap(State, S). |
Dan Rosen (mergeconflict) said: If |
@Blaisorblade said: |
@adriaanm said: |
@SethTisue said: |
@milessabin said: |
@etorreborre said: |
Stephen Compall (s11001001) said: |
Jed Wesley-Smith (jedws) said: |
Matthew Pocock (drdozer) said:
There are various implicit instances with RangeAs.Aux[X]#l as one of their type parameters. They are not found in all situations if I attempt to summon them using the lambda. However, if I do this:
Now if I summon them using RangeAsX, they are found. |
@ijuma said: |
@milessabin said: |
@milessabin said: |
@adriaanm said: |
implement what's described in "Partial polymorphic type inference and higher-order unification"
The text was updated successfully, but these errors were encountered: