X
in type HKId[A[X]] = ...
is a higher order type parameter. It is scoped to the type parameter clause, usually referenced in a type constraint. See §4.4 of the spec:
The above scoping restrictions are
generalized to the case of nested type
parameter clauses, which declare
higher-order type parameters.
Higher-order type parameters (the type
parameters of a type parameter t ) are
only visible in their immediately
surrounding parameter clause (possibly
including clauses at a deeper nesting
level) and in the bounds of t .
Therefore, their names must only be
pairwise different from the names of
other visible parameters. Since the
names of higher-order type parameters
are thus often irrelevant, they may be
denoted with a ‘_’, which is nowhere
visible.
A while back, we discussed the possibility of adding a literal syntax for type functions, e.g. [A] Either[Int, A]
. This would be really useful in Scalaz. In the meantime, we use the trick from Alexey's answer, expressed in the PartialApplyXofY traits. Inference would be even better, but that's much trickier, despite the innocuous entry in Trac!)
Anyway, during that thread, Adriaan mentioned:
It obviously won't be trivial to
implement everything that logically
follows from having anonymous type
functions, as we currently don't have
the necessary infrastructure to allow
people to write higher-kinded type
aliases, for example:
type MyTypeFun = [X, Y] Pair[Y, X] //
desirable, but hard to support with
the current implementation (we look at
the type params of a symbol to infer
its kind)