In C++ I can do the following:
template<typename T, typename V>
struct{
void operator()(T _1, V _2){
_2.foo( _1 );
}
};
which lets me arbitrarily decide to use any object which has some method called "foo" that takes some type "T" without specifying in advance either the argument type of the "foo" function nor the return type of said function.
When I look at Scala, see traits like Function1, and am playing around with function definitions like
def foo[T<:{def foo():Unit}]( arg:T ) = //something
def bar( x:{def foo():Unit} ) = //something
def baz[T,V<:Function1[T,_]]( x:T, y:V ) = y( x )
I look at myself and think why can't I do the same thing? Why does "baz" return an Any? Can't it deduce the actual return type at compile time? Why do I have to declare the return type of "foo" if I might not even use it?
I'd like to be able to do
def biff[T,V:{def foo( x:T ):Unit}] = //something
or
def boff[T<:{def foo( x:Double ):_}]( y:T ) = y.foo _
Can you do this and am I just missing something? Or if not, why not?
biff
example. Is there a missing argument? – Gronseth