Skip to content

Instantly share code, notes, and snippets.

@taku0
Created July 6, 2011 10:59
Show Gist options
  • Save taku0/1067005 to your computer and use it in GitHub Desktop.
Save taku0/1067005 to your computer and use it in GitHub Desktop.
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
}
}
// これでも通らない
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
}
}
// これは通る
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
}
}
// これは通らない
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