What is the function of Scala non-value type
In this issue, Xiaobian will bring you about the role of Scala non-value types. The article is rich in content and analyzed and described from a professional perspective. After reading this article, I hope you can gain something.
method type
The method type is represented internally as (Ts)U, which is a sequence of types (T1,..., Tn) n>=0, U is a (value or method) type. This type represents a named method whose parameters are of type T1,..., Tn, the type of return result is U.
The method type is right associative, and the way (Ts1)(Ts2)U is processed is (Ts1)(Ts2)U).
A special case is a method type with no parameters. It can be written in the form =>T. The parameterless method name expression is evaluated each time the name is referenced.
Method types do not exist as types of values. If a 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 statement:
def a: Int
def b (x: Int): Boolean
def c (x: Int)(y: String, z: String): String
The following types are generated:
a: => Int
b: (Int) Boolean
c: (Int)(String, String) String
polymorphic method type
Polymorphic method types are represented internally as [tps]T,[tps] is the type parameter part [a1 >: L1 : Ln =0, T is a (value or method) type. This type represents an array with S1,..., Sn is a naming method for type parameters and produces results of type T, parameter types S1,..., Sn and lower bound L1,..., Ln and upper bound U1,..., Un consistent (§3.2.4).
Example 3.3.2 The following statement:
def empty[A]: List[A]
def union[A : Nothing : Nothing : L1 : Ln