You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
traitTraversable[+A] {
defflatMap[B](f: A=>Traversable[B]):Traversable[B] =???
}
traitIterable[+A] extendsTraversable[A] {
defflatMap[B](f: A=>Iterable[B]):Iterable[B] =???
}
traitSeq[+A] extendsIterable[A] {
defflatMap[B](f: A=>Seq[B]):Seq[B] =???
}
objectTestextendsApp {
vala:Seq[Int] =newSeq[Int] {}
valb:Iterable[Int] =newIterable[Int] {}
a.flatMap(i => b) //!! changing the argument to ((i: Int) => b) works
}
The type of the argument of the method flatMap is one of Int=>Traversable[Int]; Int=>Iterable[Int] or Int=>Seq[Int].
Obviously the type of the variable i must be Int, however the type inferrer fails to infer this, causing the compilation to fail. Once designated the type of i as Int, the compilation went on smoothly.
I think the type would be rather obvious to be inferred but Scala compiler cannot.
The text was updated successfully, but these errors were encountered:
The type of the argument of the method flatMap is one of Int=>Traversable[Int]; Int=>Iterable[Int] or Int=>Seq[Int].
Obviously the type of the variable i must be Int, however the type inferrer fails to infer this, causing the compilation to fail. Once designated the type of i as Int, the compilation went on smoothly.
I think the type would be rather obvious to be inferred but Scala compiler cannot.
The text was updated successfully, but these errors were encountered: