I can define a function that accepts a Seq[Char]
def f(s: Seq[Char]) = s
and it works if I pass in a String:
scala> f("this")
res8: Seq[Char] = this
which means that I can use it in a map:
scala> List("this").map(s => f(s))
res9: List[Seq[Char]] = List(this)
So why can’t I do this?:
scala> List("this").map(f)
<console>:10: error: type mismatch;
found : Seq[Char] => Seq[Char]
required: java.lang.String => ?
List("this").map(f)
^
You can’t do that because there is no promotion of an implicit conversion
A => BtoF[A] => F[B]. In particular,fis actually an instance of typeSeq[Char] => Seq[Char], and you would require that the implicit conversion fromString => Seq[Char]would generate a functionString => Seq[Char]. Scala doesn’t do two-step implicit conversions such as this.If you write
s => f(s), Scala is free to fiddle with the types so thatsis converted toSeq[Char]before being passed in tof.