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

Question about currying and ambiguous method call

No replies
Thomas Pawlitzki
Joined: 2009-01-07,
User offline. Last seen 42 years 45 weeks ago.

Hallo NG,

I have a problem with a curried method.

I define an object with two functions.
Simplyfied it looks like:

object A {
def test(param1 : Int)(param2 : Int) {
// do something
}
def test(param1 : Int) {
// Do something else
}
}

So far so good.
This pice of code produces no error.
But when I try to call one of the overloaded(?) function I get an error

A.test(5)
A.test(2) {
6
}

"ambiguous reference to overloaded definition, both method test in
object A of type (Int)Unit and
method test in object A of type (Int)(Int)Unit match argument types (Int)"

But how can I overload the method correctly so that one method waits
for only one parameter and the other one waits for two.
If I write the methods without currying one it works as expected, but
I can not use this nice feature of putting the 2nd single argument in
{}.

Thanks for your help!

Cheers,
Thomas

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