All partial unification algorithms failed on implicit conversion from functions - How to improve in Scala?

66 Views Asked by At

Here is a simple example:

object UnificationOnConversionFromFn {

  trait :=>[I, R]

  implicit def fromVanilla[I, R](
      vanilla: I => R
  ): I :=> R = ??? // fail

  implicit def fromVanilla2[I, R, F <: I => R](
      vanilla: F
  ): I :=> R = ??? // fail

  implicit def fromVanilla3[I, R, F[A, B] <: A => B](
      vanilla: F[I, R]
  ): I :=> R = ??? // fail

  lazy val _fn0: Int :=> Int = {

    val a: Int :=> Int = fromVanilla { v =>
      v + 1
    }

    val b: Int :=> Int = { v =>
      v + 1
    }

    b
  }
}

despite the fact that any implicit function can be used to make it compile, they all failed:

UnifyingConversionFromFn.scala:27:28: missing parameter type

How to make any of them work? Any measure (except rewritng the code) is acceptable - macros, compiler options, compiler plugins, experimental compilers, you name it.

This is merely a simple case in compiler type unification, it shouldn't take artificial super-intelligence to solve

0

There are 0 best solutions below