The following types do not represent a collection of values, nor do they appear explicitly in the program. They are only introduced with the internal type of the defined identifier.
Method type
The method type is internally expressed as (ts) U, (TS) is a type sequence (T1,..., Tn) N>=0,u is a (value or method) type. This type represents a named method whose parameter type is T1,..., Tn, and the type of the returned result is U.
The method type is right-associative, (TS1) (TS2) U is processed in the Way (TS1) ((TS2) u).
A special case is a method type that has no parameters. Can be written in the form of a =>t. The parameterless method name expression will be evaluated each time the name is referenced.
The method type does not exist in the form of a value type. If the method name is referenced as a value, its type is automatically converted to the corresponding function type (§6.25).
Example 3.3.1 the following declaration:
def A:int
def B (x:int): Boolean
def C (x:int) (y:string, z:string): String
The following types are produced:
A: = = Int
B: (Int) Boolean
C: (Int) (String, String) string
Polymorphic Method Types
The Polymorphic method type is internally expressed as [Tps]t,[tps] is a type parameter part [A1;: L1 <: U1,..., an;: Ln <: Un],n>=0,t is a (value or method) type. The type represents a named method that takes S1,..., sn as the type parameter and produces a result of type T, the parameter type S1,..., sn and the Nether L1,..., Ln and upper bound U1,..., un (§3.2.4).
Example 3.3.2 the following declaration:
def Empty[a]: list[a]
def union[a <:comparable[a] [x:set[a], Xs:set[a]): Set[a]
The following types are generated:
Empty: [A;: Nothing <:] List[a]
Union: [A;: Nothing <: Comparable[a]] (X:set[a], xs:set[a]) Set[a]
Type constructor
The inner representation of a type constructor is similar to a polymorphic method type. [+/-A1;: L1 <: U1,..., +/-an;: Ln <: Un] T represents a type that is expected to be a type constructor parameter (§4.4) or an abstract type constructor binding (§4.3) with a corresponding type parameter clause.
Example 3.3.3 The following is a fragment of class Iterable[+x]:
Trait iterable[+x]{
def flatmap[newtype[+x]<:iterabe[x],s] (f:x = Newtype[s]): Newtype[s]
}
Conceptually, the type constructor iterable is the name of the anonymous type [+x] iterable[x],
Flatmap passed to the Newtype type constructor parameter.
Scala non-value types