This page is no longer maintained — Please continue to the home page at www.scala-lang.org

wrong number of paramaters: expected = 1

1 reply
Skavookie
Joined: 2011-02-20,
User offline. Last seen 1 year 24 weeks ago.

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.

Florian Hars 3
Joined: 2011-05-08,
User offline. Last seen 42 years 45 weeks ago.
Re: wrong number of paramaters: expected = 1

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

Copyright © 2012 École Polytechnique Fédérale de Lausanne (EPFL), Lausanne, Switzerland