-
-
Save markhibberd/4441372 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
object T { | |
implicit def XIntToInt(x: XInt): Int = x.n | |
// isomorphism to Int | |
case class XInt(n: Int) | |
case class Wibble[A](a: A) { | |
def wibble(implicit ev: A <:< Int) = a + 9 | |
def map[B](f: A => B) = | |
Wibble(f(a)) | |
} | |
object Wobble { | |
def wobble[A](w: Wibble[A])(implicit ev: A => Int) = | |
w.map(x => ev(x)).wibble | |
implicit def wibblable[A](w: Wibble[A])(implicit ev: A => Int): Wibble[Int] = | |
w.map(x => ev(x)) | |
val w1 = Wibble(3) | |
// fine | |
w1.wibble | |
val w2 = Wibble(XInt(3)) | |
// one of: | |
wobble(w2) | |
(w2: Wibble[Int]).wibble | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment