Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><code>X</code> in <code>type HKId[A[X]] = ...</code> 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:</p> <blockquote> <p>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.</p> </blockquote> <p>A while back, we discussed the possibility of adding a literal syntax for type functions, e.g. <code>[A] Either[Int, A]</code>. This would be really useful in Scalaz. In the meantime, we use the trick from Alexey's answer, expressed in the <a href="http://github.com/scalaz/scalaz/blob/master/core/src/main/scala/scalaz/PartialApplys.scala" rel="nofollow noreferrer">PartialApplyXofY traits</a>. Inference would be even better, but that's much trickier, despite the <a href="http://lampsvn.epfl.ch/trac/scala/ticket/2712" rel="nofollow noreferrer">innocuous entry in Trac</a>!)</p> <p>Anyway, during that thread, <a href="http://article.gmane.org/gmane.comp.lang.scala.internals/3051/match=types+notation+compostion" rel="nofollow noreferrer">Adriaan mentioned</a>:</p> <blockquote> <p>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:</p> <p>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)</p> </blockquote> <p><strong>UPDATE</strong></p> <p>Turns out you can get pretty close already:</p> <pre><code>def hk[_[_]] = (); hk[({type A[X] = X})#A] </code></pre> <p>Or getting a little creative:</p> <pre><code>def hk[_[_]] = (); hk[({type \[X] = X}) # \ ] def hk[_[_]] = (); hk[({type λ[α]=α})#λ ] </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload