Created
July 6, 2011 10:59
-
-
Save taku0/1067005 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
class Foo | |
object Main { | |
def hoge[A](fooCompatible: A)(implicit converter: Converter[A]) = { | |
} | |
def main(args: Array[String]) { | |
hoge(new Foo)(Converter.identity) // この行を消すと下の行もエラーになる | |
hoge(new Foo) | |
} | |
} | |
trait Converter[A] extends (A => Foo) { | |
} | |
object Converter { | |
implicit val identity = new Converter[Foo] { | |
def apply(foo: Foo) = foo | |
} | |
} |
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
// これでも通らない | |
class Foo | |
object Main { | |
def hoge[A](fooCompatible: A)(implicit converter: Converter[A]) = { | |
} | |
def main(args: Array[String]) { | |
println(Converter.x) | |
// hoge(new Foo)(Converter.identity) | |
hoge(new Foo) | |
} | |
} | |
trait Converter[A] extends (A => Foo) { | |
} | |
object Converter { | |
val x = 1 | |
implicit val identity = new Converter[Foo] { | |
def apply(foo: Foo) = foo | |
} | |
} |
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
// これは通る | |
class Foo | |
object Main { | |
def hoge[A](fooCompatible: A)(implicit converter: Converter[A]) = { | |
} | |
def main(args: Array[String]) { | |
// hoge(new Foo)(Converter.identity) | |
hoge(new Foo) | |
} | |
} | |
trait Converter[A] extends (A => Foo) { | |
} | |
object Converter { | |
implicit val identity: Converter[Foo] = new Converter[Foo] { | |
def apply(foo: Foo) = foo | |
} | |
} |
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
// これは通らない | |
class Foo | |
object Main { | |
def hoge[A](fooCompatible: A)(implicit converter: Converter[A]) = { | |
} | |
def main(args: Array[String]) { | |
// hoge(new Foo)(Converter.identity) | |
hoge(new Foo) | |
} | |
} | |
trait Converter[A] extends (A => Foo) { | |
} | |
object Converter { | |
val i: Converter[Foo] = new Converter[Foo] { | |
def apply(foo: Foo) = foo | |
} | |
implicit val identity = i | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment