- About Scala
- Documentation
- Code Examples
- Software
- Scala Developers
Question about currying and ambiguous method call
Thu, 2009-03-19, 20:58
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