The difference between declaring members of a higher class

Looking at the sources for the shapeless library, I drew attention to the various declarations of a member of a higher type and wondered if he had any particular difference in use. For example, a common attribute here :

trait Generic1[F[_], FR[_[_]]] { type R[t] // ... } trait IsHCons1[L[_], FH[_[_]], FT[_[_]]] { type H[_] // ... } 

One type member is declared with common syntax for type constructors (ie H[_] ) and Generic1 has R[t] . Although auxiliary type aliases are defined in the same way:

 object Generic1 { type Aux[F[_], FR[_[_]], R0[_]] = Generic1[F, FR] { type R[t] = R0[t] } // ... } object IsHCons1 { type Aux[L[_], FH[_[_]], FT[_[_]], H0[_], T0[_] <: HList] = IsHCons1[L, FH, FT] { type H[t] = H0[t] ; type T[t] = T0[t] } // ... } 

So, is it interesting that R[t] and H[_] have any difference or not?

+5
source share
1 answer

There is no difference since t simply unconnected. You can easily check this in the REPL:

 scala> type T1 = { type R[t] } defined type alias T1 scala> type T2 = { type R[_] } defined type alias T2 scala> implicitly[T1 =:= T2] res0: =:=[T1,T2] = <function1> 

The fact that compiling the last line proves that the compiler sees T1 and T2 as the same type.

+6
source

All Articles