Skip to content

Instantly share code, notes, and snippets.

@tonymorris
Created January 3, 2013 06:38
Show Gist options
  • Save tonymorris/4441295 to your computer and use it in GitHub Desktop.
Save tonymorris/4441295 to your computer and use it in GitHub Desktop.
object T {
// isomorphism to Int
case class XInt(n: Int)
case class Wibble[A](a: A) {
def wibble(implicit ev: A <:< Int) = a + 9
}
object Wobble {
val w1 = Wibble(3)
// fine
w1.wibble
val w2 = Wibble(XInt(3))
// not fine, even though XInt ~ Int
// w2.wibble
}
}
@tonymorris
Copy link
Author

object T {
  // 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 {
    val w1 = Wibble(3)
    // fine
    w1.wibble
    val w2 = Wibble(XInt(3))
    // passes the compiler, but not acceptable for all cases
    w2.map(_.n).wibble
    val w3 = Wibble(XInt(3))
    // not fine, even though XInt ~ Int
    // w3.wibble
  }

}

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment