![]() ![]() For simplicity, we omit environments and constraints. The following rules apply to match types. existing variables in the constraint cannot be instantiated by matching the scrutinee against the patterns. In the context of reduction, the subtyping test S <: P is understood to leave the bounds of all variables in the input constraint unchanged, i.e. ![]() The full formulation of subtyping tests describes them as a function from a constraint and a pair of types to either success and a new constraint or failure. Here, "small" and "large" are understood with respect to <.įor simplicity, we have omitted constraint handling so far. ![]() An instantiation Is is minimal for Xs if all type variables in Xs that appear covariantly and nonvariantly in Is are as small as possible and all type variables in Xs that appear contravariantly in Is are as large as possible. Type parameters in patterns are minimally instantiated when computing S <: Pi. Singleton paths to distinct values are nonintersecting, such as object definitions or singleton enum cases.Constant types with distinct values are nonintersecting.If such proof is found, proceed to the next case ( Pi+1), otherwise, do not reduce.ĭisjointness proofs rely on the following properties of Scala types:.Otherwise, try constructing a proof that S and Pi are disjoint, or, in other words, that no value s of type S is also of type Pi.If the scrutinee type S is an empty set of values (such as Nothing or String & Int), do not reduce.The compiler implements the following reduction algorithm: Match type reduction follows the semantics of match expressions, that is, a match type of the form S match evaluates to a value of type Ti for all s: S. The scrutinee, bound, and pattern types must all be first-order types. We will leave it out in places where it does not matter for the discussion. So each case is either a unary function type or a type lambda over a unary function type.ī is the declared upper bound of the match type, or Any if no such bound is given. If there are no bound type variables in a case, the type parameter clause is omitted and only the function type P => T is kept. Here, is a type parameter clause of the variables bound in pattern Pi. ![]()
0 Comments
Leave a Reply. |