Skip to content

Instantly share code, notes, and snippets.

@kmizu
Forked from tototoshi/1.scala
Created October 16, 2012 13:10
Show Gist options
  • Save kmizu/3899178 to your computer and use it in GitHub Desktop.
Save kmizu/3899178 to your computer and use it in GitHub Desktop.
(implicit conversions + method values) cause strange problem
Welcome to Scala version 2.9.1.final (Java HotSpot(TM) 64-Bit Server VM, Java 1.
7.0_03).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import scala.collection.immutable.StringLike
import scala.collection.immutable.StringLike
scala> "a".format(_)
res0: Any* => String = <function1>
scala> "a".format(_: String)
res1: String => String = <function1>
scala> "a".format(_: String, _: String)
res2: (String, String) => String = <function2>
scala> "a".format(_: String, _: String, _: Int)
res3: (String, String, Int) => String = <function3>
scala> "a".format _
<console>:9: error: missing arguments for method format in trait StringLike;
follow this method with `_' if you want to treat it as a partially applied function
"a".format _
^
scala> ("a":StringLike[String]).format _
res5: Any* => String = <function1>
@tototoshi
Copy link

scala> class A
defined class A

scala> class B(a: A) { def f(i: Int) = i }
defined class B

scala> implicit def a(a: A): B = new B(a)
a: (a: A)B

scala> val a = new A
a: A = A@768d26dd

scala> a.f(1)
res11: Int = 1

scala> a.f(_)
res12: Int => Int = <function1>

scala> a.f _
<console>:17: error: missing arguments for method f in class B;
follow this method with `_' if you want to treat it as a partially applied function
              a.f _

scala> (a: B).f _
res15: Int => Int = <function1>

implicit conversion が関係あるみたいですねえ

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