Here is the exact situation I am in (I do not want to simplify it for fear of missing out the cause of the error):
In the framework I am working in there is a
trait RequestHeader{...}
and another trait
trait Request[+A] extends RequestHeader{...}
There is a function that expects to receive an argument of type:
def f(arg: RequestHeader => Result) = {...}
I would expect to be able to pass in
arg': Request[AnyContent] => Result
However, this causes the compiler to complain. Why is this?
Function1is contravariant in its input type, which makes sense if you think about it. Consider the following simpler example:If I give
fa function of typeBar => Foo, it’s not going to be able to apply that toBaz. (A function of typeFoo => Bar, on the other hand, would be perfectly fine.)