Hi all,
I have tried to send a message previously and I think it did not work so please excuse me if I sent it twice.
I have tried to use implicit arguments which are identified by traits and not objects and have found out that the type inference mechanism of the partially-applied function does not infer the type I need (as the implicit parameter is the last argument for a curried function).
The point is that for the same none curried version the type inference was inferring the type I needed and I wanted to ask if there is a way to hint somehow about the right type without giving it explicitly.
An example is:
----
class A
trait T
trait Printer[S <: T] {def print():Unit}
----
The version with currying:
----
def pr[S1 <: A, S2 <: T](a: S1 with S2)(implicit p: Printer[S2]) = p.print() // the implicit keyword can be removed
pr(new A with T)(new Printer[T] {def print() = Console.println("1")})
----
This throws the following error:
<console>:9: error: type mismatch;
found : java.lang.Object with Printer[T]{ ... }
required: Printer[A with T{ ... }]
pr(new A with T)(new Printer[T] {def print() = Console.println("1")})
^
When doing it without currying the required type of the Printer is correct. It is also correct in the curried version when I supply the Type explicitly to the 'pr' method (i.e. pr[T](new A with T)).
Shouldnt the type parameters in the two versions of pr be the same? The main problem is that traits are not identified (at least in anonymous classes) and only the superclass is, is there a way to tell the type inference mechanism about the traits in a type parameter?
I am new to Scala and would appreciate any help,
Thanks,
Tomer