- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
wrong number of paramaters: expected = 1
Tue, 2011-09-20, 21:43
I get a “wrong number of paramaters: expected = 1” when I complies
line that defs “dot” and “+”:
case class Vector(vector: Double*) {
def dot(o: Vector): Double = (vector zip o.vector).map((a,b) =>
a*b).foldLeft(0D)((a,b) => a+b)
def +(o: Vector): Vector = Vector((vector zip o.vector).map((a,b) =>
a+b): _*)
...
}
Help! I've been starting at these lines for several days.
On Tue, Sep 20, 2011 at 01:43:03PM -0700, Joshua Gooding wrote:
> ...map((a,b) => ... )
This passes a function with two parameters to map, which
expects a function with one parameter. (Yes, tuples and
function argument lists can be confusing). Solutions:
...map( s => { val a=s._1; val b=s._2; ... })
...map{ case (a,b) => ... }
- Florian