View Borders for Higher Type Types

I am trying to set a view restriction on a high level type and I get an error message that I cannot understand.

$ scala -language:higherKinds
Welcome to Scala version 2.10.0 (Java HotSpot(TM) 64-Bit Server VM, Java 1.6.0_43).
Type in expressions to have them evaluated.
Type :help for more information.

scala> trait F[M[_]]
defined trait F

scala> def foo[M[_]](implicit m: M[_] => F[M]) = 42
foo: [M[_]](implicit m: M[_] => F[M])Int

scala> def bar[M[_] <% F[M]] = 42
<console>:8: error: type M takes type parameters
       def bar[M[_] <% F[M]] = 42
                    ^

Shouldn't barthe same be compiled as foo? What am I missing?

+5
source share
1 answer

Note that there is a subtle difference between M[_]the type parameter list and the type M[_](i.e., it M[_]plays a role in the function type in the list of implicit parameters). The first is the type constructor parameter, and the second is the existential type (see Sections 4.4 and 3.2.10 of the Scala language specification for more information).

, , M[_] M[X] , ​​ ( - M[X] forSome { type X }).

( ):

scala> def bar[M[_], M_ <: M[_] <% F[M]] = 42
bar: [M[_], M_ <: M[_]](implicit evidence$1: M_ => F[M])Int

M[_] , ( M_) .

Scala M[_] <% F[M] , , , , - , , .

+6

All Articles