Last active
May 3, 2019 09:53
-
-
Save slouc/036319297a4e2c548583e48303581230 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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