Skip to content

Instantly share code, notes, and snippets.

@slouc
Last active May 3, 2019 09:53
Show Gist options
  • Save slouc/036319297a4e2c548583e48303581230 to your computer and use it in GitHub Desktop.
Save slouc/036319297a4e2c548583e48303581230 to your computer and use it in GitHub Desktop.
// add scalacOptions += "-Ypartial-unification" to build.sbt
import scala.reflect.runtime._, universe._
import scala.language.higherKinds
def checkUnification[F[_], A: TypeTag](fa: => F[A]) = s"${typeOf[A]}"
assert(checkUnification(e) == "String")
assert(checkUnification(f) == "List[Int]")
implicit class InferToLeft[M[_, _], A, B](a: M[A, B]) {
def lefty: InferToLeft.U[M, B, A] = a
}
object InferToLeft {
type U[M[_, _], B, A] = M[A, B]
}
def e: Either[Int, String] = ???
def f: AnyRef => List[Int] = ???
assert(checkUnification(e.lefty) == "Int")
assert(checkUnification(f.lefty) == "AnyRef")
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment