Spec2.8Chap3b

3.3 非値型 (Non-Value Types)

The types explained in the following do not denote sets of values, nor do they appear explicitly in programs.They are introduced in this report as the internal types of defined identifiers.

次に説明する型は、値の集合を表しているわけではなく、 また、プログラム中に明示的に現れるわけではありません。 これらは、定義された識別子の内部型としてこのレポートで紹介しています。



3.3.1 メソッド型

A method type is denoted internally as (Ps)U , where (Ps) is a sequence of parameter names and types (p1 : T1,...,pn : Tn) for some n >= 0 and U is a (value or method) type. This type represents named methods that take arguments named p1,...,pn of types T1,...,Tn and that return a result of type U .

Method types associate to the right: (Ps1)(Ps2)U is treated as (Ps1)((Ps2)U).

メソッド型は、内部的に (Ps)U として表現されます。ここで (Ps) はパラメータ名と型の並び (p1 : T1,...,pn : Tn)、U は (値またはメソッド) 型です(n >= 0)。 この型は、 型 T1,...,Tn の p1,...,pn という名前の引数をとり、 型 U の結果を返す、名前付きメソッドとして表現されます。

メソッド型は右結合です。: すなわち、(Ps1)(Ps2)U は (Ps1)((Ps2)U) として扱われます。

A special case are types of methods without any parameters. They are written here => T. Parameterless methods name expressions that are re-evaluated each time the parameterless method name is referenced.

特別な場合として、いかなるパラメータもとらないメソッドの型があります。それらは ここでは「 => T」と書きます。 パラメータなしのメソッドは、パラメータなしのメソッド名が参照される度に再評価 される式に対して名前を与えます。

Method types do not exist as types of values. If a method name is used as a value, its type is implicitly converted to a corresponding function type (§6.26).

メソッド型は、値の型としては存在しません。 もしメソッド名が値として使われるなら、 その型は暗黙のうちに対応する関数型に変換されます (§6.26)。


Example 3.3.1 : 宣言

   def a: Int 
   def b (x: Int): Boolean 
   def c (x: Int) (y: String, z: String): String

produce the typings

は、次の型付けを生みます。

   a: => Int 
   b: (Int) Boolean 
   c: (Int) (String, String) String



3.3.2 多相的メソッド型 (Polymorphic Method Types)

A polymorphic method type is denoted internally as [tps]T , where [tps] is a type parameter section [a1 >: L1 <: U1,...,an >: Ln <: Un] for some n >= 0 and T is a (value or method) type. This type represents named methods that take type arguments S1,...,Sn which conform (§3.2.4) to the lower bounds L1,...,Ln and the upper bounds U1,...,Un and that yield results of type T .

多相的メソッド型は、内部的に [tps]T として表現されます。ここで n >= 0、 [tps] は型パラメータ部 [a1 >: L1 <: U1,...,an >: Ln <: Un]であり、 T は(値あるいはメソッドの)型です。 この型は、下限境界 L1,...,Ln と上限境界 U1,...,Un に適合する(§3.2.4) 型引数 S1,...,Sn をとり、型 T の結果をもたらす、 名前付きメソッドとして表現されます。


Example 3.3.2 : 宣言

   def empty[A]: List[A] 
   def union[A <: Comparable[A]] (x: Set[A], xs: Set[A]): Set[A]

は、次の型付けを生みます。

   empty : [A >: Nothing <: Any] List[A] 
   union : [A >: Nothing <: Comparable[A]] (x: Set[A], xs: Set[A]) Set[A] 



3.3.3 型コンストラクタ (Type Constructors)

A type constructor is represented internally much like a polymorphic method type. [± a1 >: L1 <: U1,...,± an >: Ln <: Un] T represents a type that is expected by a type constructor parameter (§4.4) or an abstract type constructor binding (§4.3) with the corresponding type parameter clause.

型コンストラクタは内部的に、多相的メソッド型とほとんど同じように表現されます。 [± a1 >: L1 <: U1,..., ± an >: Ln <: Un]T は、型コンストラクタパラメータ (§4.4)あるいは、 対応する型パラメータ節をもつ抽象型コンストラクタ束縛 (§4.3) によって要請される型を表します。


Example 3.3.3 : 次の 断片的な Iterable[+X]クラスについて考えます。

   trait Iterable[+X] {
     def flatMap[newType[+X] <: Iterable[X], S](f: X => newType[S]): newType[S]
   }

Conceptually, the type constructor Iterable is a name for the anonymous type [+X] Iterable[X], which may be passed to the newType type constructor parameter in flatMap.

概念的には、型コンストラクタ Iterable は、 flatMap 中の型コンストラクタパラメータ newType に渡される、 無名の型 [+X] Iterable[X] の名前です。



3.4 基本型とメンバー定義 (Base Types and Member Definitions)

Types of class members depend on the way the members are referenced. Central here are three notions, namely:

  1. the notion of the set of base types of a type T ,
  2. the notion of a type T in some class C seen from some prefix type S,
  3. the notion of the set of member bindings of some type T .

クラスメンバの型は、メンバーが参照される方法に依存します。 3 つの主要な概念があります。

  1. 型 T の基本型の集合としての概念。
  2. ある前置型 S からみた、あるクラス C 中の、型 T としての概念。
  3. ある型 T のメンバー束縛の集合としての概念。

これらの概念は、次のように相互に再帰的に定義されます。

1. The set of base types of a type is a set of class types, given as follows.

  • The base types of a class type C with parents T1,...,Tn are C itself, as well as the base types of the compound type T1 with ... with Tn {R}.
  • The base types of an aliased type are the base types of its alias.
  • The base types of an abstract type are the base types of its upper bound.
  • The base types of a parameterized type C[T1,...,Tn] are the base types of type C , where every occurrence of a type parameter ai of C has been replaced by the corresponding parameter type Ti .
  • The base types of a singleton type p.type are the base types of the type of p.

1. ある型の基本型の集合は、次で与えられるクラス型の集合です。

  • 親 T1,...,Tn をもつクラス型 C の基本型は、複合型 T1 with ... with Tn {R}の基本型と同様、C 自身。
  • エイリアスされた型の基本型は、そのエイリアスの基本型。
  • 抽象型の基本型は、その上限境界の基本型。
  • パラメータ化された型 C[T1,...,Tn] の基本型は、型 C の基本型。ここで C の型パラメータ ai の出現を対応するパラメータ型 Ti で置き換えたとします。
  • シングルトン型 p.type の基本型は、p の型の基本型。
  • The base types of a compound type T1 with ... with Tn {R} are the reduced union of the base classes of all Ti's. This means: Let the multi-set SS be the multi-set-union of the base types of all Ti's. If SS contains several type instances of the same class, say Si#C[T1,...,Tin] (i ∈ I), then all those instances are replaced by one of them which conforms to all others. It is an error if no such instance exists. It follows that the reduced union, if it exists, produces a set of class types, where different types are instances of different classes.
  • 複合型 T1 with ... with Tn {R} の基本型は、すべての Ti の基底クラスの 縮小和集合(reduced union) 。 これは次を意味します:マルチ集合 SS をすべての Ti の基本型のマルチ集合の和とします。もし SS が同じクラスの型インスタンスをいくつか含むなら、例えば S i #C[T i 1,...,T i n] (i ∈ I)、それらすべてのインスタンスを、その他のすべてに適合するものの1つで置き換えます。もしそのようなインスタンスが存在しないなら、エラーです。したがって、縮小和集合は、もしそれが存在するなら、異なる型は異なるクラスのインスタンスであるような、クラス型の集合を作り出します。
  • The base types of a type selection S#T are determined as follows. If T is an alias or abstract type, the previous clauses apply. Otherwise, T must be a (possibly parameterized) class type, which is defined in some class B . Then the base types of S#T are the base types of T in B seen from the prefix type S.
  • The base types of an existential type T forSome { Q } are all types S forSome { Q } where S is a base type of T .
  • 型選択 S#T の基本型は、次のように決定されます。もし T がエイリアスあるいは抽象型なら、上述が適用されます。そうでなければ T は、あるクラス B で定義された (パラメータ化されていてもよい) クラス型でなければなりません。このとき S#T の基本型は、前置型 S から見た B 中の T の基本型です。
  • 存在型 T forSome { Q } の基本型は、すべての S forSome { Q } 型。ここで S は T の基本型とします。

2. The notion of a type T in class C seen from some prefix type S makes sense only if the prefix type S has a type instance of class C as a base type, say S´#C[T1,...,Tn]. Then we define as follows.

  • If S = ε.type, then T in C seen from S is T itself.
  • Otherwise, if S is an existential type S´ forSome { Q }, and T in C seen from S´ is T´ , then T in C seen from S is T´ forSome { Q }.

2. ある 前置型 S からみたクラス C 中の型 T という考えは、 前置型 S がクラス C の型インスタンスを基本型として持つ場合に限り 意味を持ちます。例えば S´#C[T1,...,Tn]。 このとき、次のように定義します。

  • もし S = ε.type なら、S から見た C 中の T は、T 自身です。
  • そうでなければ、もし S が存在型 S´ forSome { Q }で、S´から見た C 中の T が T´なら、S から見た C 中の T は、T´ forSome { Q } です。
  • Otherwise, if T is the i'th type parameter of some class D, then
    • If S has a base type D[U1,...,Un], for some type parameters [U1,...,Un], then T in C seen from S is Ui .
    • Otherwise, if C is defined in a class C´ , then T in C seen from S is the same as T in C´ seen from S´ .
    • Otherwise, if C is not defined in another class, then T in C seen from S is T itself.
  • そうでなければ、もし T があるクラス D の i 番目の型パラメータなら、
    • もし S がある型パラメータ [U1,...,Un] に対して基本型 D[U1,...,Un] を持つなら、S から見た C 中の T は Ui です。
    • そうでなければ、もし C がクラス C´ 中で定義されていれば、S から見た C 中の T は、S´から見た C´中の T と同じです。
    • そうでなければ、もし C が他のクラス中で定義されていないなら、S から見た C 中の T は T 自身です。
  • Otherwise, if T is the singleton type D.this.type for some class D then
    • If D is a subclass of C and S has a type instance of class D among its base types, then T in C seen from S is S.
    • Otherwise, if C is defined in a class C´, then T in C seen from S is the same as T in C´ seen from S´ .
    • Otherwise, if C is not defined in another class, then T in C seen from S is T itself.
  • If T is some other type, then the described mapping is performed to all its type components.
  • そうでなければ、もし T があるクラス D に対するシングルトン型 D.this.type なら、
    • もし D が C のサブクラスで、S がその基本型の中にクラス D の型インスタンスをもっているなら、S から見た C 中の T は S です。
    • そうでなければ、もし C がクラス C´中で定義されているなら、S から見た C 中の T は、S´から見た C´中の T と同じです。
    • そうでなければ、もし C が他のクラス中で定義されていないなら、S から見た C 中の T は T 自身です。
  • もし T が他のある型なら、ここで記述したマッピングをそのすべての型構成に対して実行します。

If T is a possibly parameterized class type, where T's class is defined in some other class D, and S is some prefix type, then we use "T seen from S" as a shorthand for "T in D seen from S".

もし T がパラメータ化されたクラス型である可能性があるとき、ただしここで T のクラスは他のあるクラス D 中で定義されていて、S が何らかの前置型であるとして、 「S から見た T 」を「S から見た D 中の T」の略記表現として使います。

3. The member bindings of a type T are (1) all bindings d such that there exists a type instance of some class C among the base types of T and there exists a definition or declaration d´ in C such that d results from d´ by replacing every type T´ in d´ by T´ in C seen from T , and (2) all bindings of the type's refinement (§3.2.7), if it has one.

3. 型 T の メンバー束縛 とは次です。 (1) T の基本型の中に何らかのクラス C の型インスタンスが存在し、 C 中の定義/宣言 d´ で、d´ 中のすべての型 T´を T から見た C 中の T´で置き換えると束縛 d が得られるような d´があるとき、 それらすべての束縛 d 。 (2) 型の細別(§3.2.7)の、 もしあれば、すべての束縛。

The definition of a type projection S#t is the member binding dt of the type t in S. In that case, we also say that S#t is defined by dt. share a to

型射影 S#tの定義 は、S 中の型 t の メンバー束縛 d t です。 この場合、S#t は d {t によって定義される}、 ともいいます。(訳注:share a to ?)



3.5 型の関係

2 つの型の関係を定義します。

   型の等価性   T≡U      T と U はあらゆるコンテキストにおいて交換可能です。
   適合性       T <: U    型 T は型 U に適合します。



3.5.1 型の等価性

Equivalence (≡) between types is the smallest congruence (*3) such that the following holds:

(*3) A congruence is an equivalence relation which is closed under formation of contexts

型の等価(≡)は、次を満たす最も小さい一致(congruence *3)です:

(*3) 一致(congruence)は、コンテキスト形成の下で閉じた等価関係です。

  • If t is defined by a type alias type t = T , then t is equivalent to T .
  • If a path p has a singleton type q.type, then p.type ≡ q.type.
  • If O is defined by an object definition, and p is a path consisting only of package or object selectors and ending in O, then O.this.type ≡ p.type.
  • もし t が型エイリアス type t = T によって定義されているなら、t は T に等価。
  • もしパス p がシングルトン型 q.type をもつなら、p.type ≡ q.type 。
  • もし O がオブジェクト定義によって定義されていて、p がパッケージあるいはオブジェクトセレクタだけからなり O の中で終わるパスなら、O.this.type ≡ p.type。
  • Two compound types (§3.2.7) are equivalent if the sequences of their component are pairwise equivalent, and occur in the same order, and their refinements are equivalent. Two refinements are equivalent if they bind the same names and the modifiers, types and bounds of every declared entity are equivalent in both refinements.
  • 2 つの複合型(§3.2.7)は、もしそれらの構成要素の並びが対で等価で、同じ順序で現れ、それらの細別が等価なら、等価です。2 つの細別は、もしそれらが同じ名前を束縛し、すべての宣言されたエンティティの修飾子、型、境界が両方の細別で等価なら、等価です、
  • Two method types (§3.3.1) are equivalent if they have equivalent result types, both have the same number of parameters, and corresponding parameters have equivalent types. Note that the names of parameters do not matter for method type equivalence.
  • 2 つのメソッド型(§3.3.1)は、もしそれらが等価な結果型を持ち、両方とも同じ数のパラメータを持ち、対応するパラメータが等価な型を持っているなら、等価です。パラメータの名前は、メソッド型の等価性では重要でないことに注意してください。
  • Two polymorphic method types (§3.3.2) are equivalent if they have the same number of type parameters, and, after renaming one set of type parameters by another, the result types as well as lower and upper bounds of corresponding type parameters are equivalent.
  • 2 つの多相的メソッド型(§3.3.2)は、もしそれらが同じ数の型パラメータを持ち、型パラメータの 1 つのセットを他の名前でリネームした後でも、その結果型が等価で、対応する型パラメータの上下限境界も等価なら、等価です。
  • Two existential types (§3.2.10) are equivalent if they have the same number of quantifiers, and, after renaming one list of type quantifiers by another, the quantified types as well as lower and upper bounds of corresponding quantifiers are equivalent.
  • 2 つの存在型(§3.2.10)は、もしそれらが同じ数の存在量化子をもち、型存在量化子の 1 つのリストを他でリネームした後でも、存在量化された型が等価で、対応する存在量化子の上下限境界も等価なら、等価です。
  • Two type constructors (§3.3.3) are equivalent if they have the same number of type parameters, and, after renaming one list of type parameters by another, the result types as well as variances, lower and upper bounds of corresponding type parameters are equivalent.
  • 2 つの型コンストラクタ(§3.3.3)は、もしそれらが同じ数の型パラメータをもち、型パラメータの 1 つのリストを他でリネームした後でも、対応する型パラメータの上下限境界や変位指定と同様にその結果型も等価なら、等価です。



3.5.2 適合性 (Conformance)

The conformance relation (<:) is the smallest transitive relation that satisfies the following conditions.

適合性の関係(<:)は、次の条件を満たす最小の推移律です。

  • Conformance includes equivalence. If T ≡ U then T <: U .
  • For every value type T , scala.Nothing <: T <: scala.Any.
  • For every type constructor T (with any number of type parameters), scala.Nothing <: T <: scala.Any.
  • For every class type T such that T <: scala.AnyRef and not T <: scala.NotNull one has scala.Null <: T .
  • 適合性は等価性を包含します。もし T≡U なら T <: U。
  • すべての値型 T について、scala.Nothing <: T <: scala.Any。
  • すべての型コンストラクタ T (型パラメータがいくつあっても)について、scala.Nothing <: T <: scala.Any。
  • T <: scala.AnyRef であり、T <: scala.NotNull1 ではないような、すべてのクラス型 T について、scala.Null <: T 。
  • A type variable or abstract type t conforms to its upper bound and its lower bound conforms to t .
  • A class type or parameterized type conforms to any of its base-types.
  • A singleton type p.type conforms to the type of the path p.
  • A singleton type p.type conforms to the type scala.Singleton.
  • A type projection T#t conforms to U#t if T conforms to U .
  • 型変数あるいは抽象型 t はその上限境界に適合し、その下限境界は t に適合します。
  • クラス型あるいはパラメータ化された型は、その基本型のいずれにも適合します。
  • シングルトン型 p.type は、パス p の型に適合します。
  • シングルトン型 p.type は、型 scala.Singleton に適合します。
  • もし T が U に適合するなら、型射影 T#t は U#t に適合します。
  • A parameterized type T[T1,...,Tn] conforms to T[U1,...,Un] if the following three conditions hold for i = 1,...,n.
  • If the i'th type parameter of T is declared covariant, then Ti <: Ui .
  • If the i'th type parameter of T is declared contravariant, then Ui <: Ti .
  • If the i'th type parameter of T is declared neither covariant nor contravariant , then Ui ≡ Ti .
  • パラメータ化された型 T[T1,...,Tn] は、もし次の 3 つの条件が i = 1,...,n に対して満たされるなら、T[U1,...,Un] に適合します 。
  • もし T の i 番目の型パラメータが共変と宣言されているなら、Ti <: Ui 。
  • もし T の i 番目の型パラメータが反変と宣言されているなら、Ui <: Ti 。
  • もし T の i 番目の型パラメータが共変でもなく反変でもないと宣言されているなら、Ui ≡ Ti 。
  • A compound type T1 with ... with Tn {R} conforms to each of its component types Ti .
  • If T <: Ui for i = 1,...,n and for every binding d of a type or value x in R there exists a member binding of x in T which subsumes d , then T conforms to the compound type U1 with ... with Un {R}.
  • The existential type T forSome { Q } conforms to U if its skolemization (§3.2.10) conforms to U .
  • The type T conforms to the existential type U forSome { Q } if T conforms to one of the type instances (§3.2.10) of U forSome { Q }.
  • 複合型 T1 with ... with Tn {R} は、その構成要素型 Ti のそれぞれに適合します。
  • もし T <: Ui (i = 1,...,n) で、R 中の型/値 x のあらゆる束縛 d について、d を包含する T 中の メンバー束縛 x が存在するなら、T は複合型 U1 with ... with Un {R} に適合します。
  • 存在型 T forSome { Q } は、もしその skolemization(§3.2.10)が U に適合するなら、U に適合します。
  • 型 T は、T が U forSome { Q } の型インスタンス(§3.2.10)の 1 つに適合するなら、存在型 U forSome { Q } に適合します。
  • If Ti ≡ T´i for i = 1,...,n and U conforms to U´ then the method type (p1 : T1,...,pn : Tn)U conforms to (p´1 : T´1,...,p´n : T´n)U´ .
  • The polymorphic type [a1 >: L1 <: U1,...,an >: Ln <: Un]T conforms to the polymorphic type [a1 >: L´1 <: U´1,...,an >: L´n <: U´n]T´ if, assuming L´1 <: a1 <: U1´,...,L´n <: an <: U´n one has T <: T´ and Li <: L´i and U´i <: Ui for i = 1,...,n.
  • もし Ti ≡ T´ (i = 1,...,n) で、U が U´に適合するなら、メソッド型 (p1 : T1,...,pn : Tn)U は (p´1 : T´1,...,p´n : T´n)U´に適合します。
  • 多相的な型 [a1 >: L1 <: U1,...,an >: Ln <: Un]T は、L´1<: a1 <: U1´,...,L´n <: an <: U´n と仮定して、もし i = 1,...,n に対して T <: T´かつ Li <: L´i かつ U´i <: Ui なら、多相的な型 [a1 >: L´1 <: U´1,...,an >: L´n <: U´n]T´に適合します。
  • Type constructors T and T´ follow a similar discipline. We characterize T and T´ by their type parameter clauses [a1,...,an] and [a´1,...,a´n], where an ai or a´i may include a variance annotation, a higher-order type parameter clause, and bounds. Then, T conforms to T´ if any list [t1,...,tn] - with declared variances, bounds and higher-order type parameter clauses - of valid type arguments for T´ is also a valid list of type arguments for T and T[t1,...,tn] <: T´[t1,...,tn]. Note that this entails that:
  • 型コンストラクタ T と T´ は、似たような規則に従います。我々は T と T´を、それらの型パラメータ節 [a1,...,an]、[a´1,...,a´n] によって特徴付けます。ここで ai あるいは a´i は変位指定アノテーション、高階の型パラメータ節、境界をもっていてもかまいません。このとき、もし T´の有効な型引数の任意のリスト [t1,...,tn] --- 宣言された変位指定、境界、高階の型パラメータ節をもっていてもよい --- もまた T の型引数の有効なリストで T[t1,...,tn] <: T´[t1,...,tn] なら、T は T´ に適合します。このことは次を必要とすることに注意してください:
  • The bounds on ai must be weaker than the corresponding bounds declared for a´i .
  • The variance of ai must match the variance of a´i , where covariance matches covariance, contravariance matches contravariance and any variance matches invariance.
  • Recursively, these restrictions apply to the corresponding higher-order type parameter clauses of ai and a´i .
  • ai の境界は、a´i に対して宣言された対応する境界よりも弱くなければならない。
  • ai の変位指定は、a´i の変位指定と一致しなければならない。ここで、共変は共変に、反変は反変に、他の任意の変位指定は不変(invariance)と一致すること。
  • これらの制限は、ai と a´i の対応する高階の型パラメータ節に再帰的に適用されます。

A declaration or definition in some compound type of class type C subsumes another declaration of the same name in some compound type or class type C´ , if one of the following holds.

もし次のうちの1つが満たされるなら、クラス型 C の何らかの複合型中の 宣言/定義は、クラス型 C´あるいは何らかの複合型中の同じ名前の 他の宣言を 包含します(subsume)

  • A value declaration or definition that defines a name x with type T subsumes a value or method declaration that defines x with type T´ , provided T <: T´ .
  • A method declaration or definition that defines a name x with type T subsumes a method declaration that defines x with type T´ , provided T <: T´ .
  • A type alias type t[T1,...,Tn] = T subsumes a type alias type t[T1,...,Tn] = T´ if T ≡ T´ .
  • A type declaration type t[T1,...,Tn] >: L <: U subsumes a type declaration type t[T1,...,Tn] >: L´ <: U´ if L´ <: L and U <: U´ .
  • A type or class definition that binds a type name t subsumes an abstract type declaration type t[T1,...,Tn] >: L <: U if L <: t <: U .
  • 型 T をもつ 名前 x を定義する値宣言/定義が、T <: T´ のときに、型 T´ をもつ x を定義する値/メソッド宣言を包含する。
  • 型 T をもつ名前 x を定義するメソッド宣言/定義が、T <: T´ のときに、型 T´ をもつ x を定義するメソッド宣言を包含する。
  • もし T≡T´なら、型エイリアス type t[T1,...,Tn] = T は型エイリアス type t[T1,...,Tn] = T´を包含します。
  • 型宣言 type t[T1,...,Tn] >: L <: U が、もし L´ <: L かつ U <: U´ ならば、型宣言 type t[T1,...,Tn] >: L´ <: U´を包含する。
  • 型名 t を束縛する型/クラス定義が、もし L <: t <: U ならば、抽象型宣言 type t[T1,...,Tn] >: L <: U を包含する。

The (<:) relation forms pre-order between types, i.e. it is transitive and reflexive. Least upper bounds and greatest lower bounds of a set of types are understood to be relative to that order.

(<:)関係は、型の間に前秩序(pre-order)を形成します。 すなわち、推移律と反射律を満たします。 型の集合の 最小の上限境界 最大の下限境界 は、 この順序に関して相対的であると考えられます。

注意: 型の集合の最小の上限境界と最大の下限境界は、常に存在するわけ ではありません。 例えば、次のクラス定義を考えてみてください。

   class A[+T] {} 
   class B extends A[B] 
   class C extends A[C]

Then the types A[Any], A[A[Any]], A[A[A[Any]]], ... form a descending sequence of upper bounds for B and C. The least upper bound would be the infinite limit of that sequence, which does not exist as a Scala type. Since cases like this are in general impossible to detect, a Scala compiler is free to reject a term which has a type specified as a least upper or greatest lower bound, and that bound would be more complex than some compiler-set limit (*4) .

(*4) The current Scala compiler limits the nesting level of parameterization in such bounds to be at most two deeper than the maximum nesting level of the operand types

このとき、型 A[Any]、A[A[Any]]、A[A[A[Any]]], ... は、B と C に対する上限境界を降順に構成します。 最小の上限境界はこのシーケンスの無限の彼方にあり、 Scala の型としては存在しません。 このような場合は一般的に検出できないので、また、 そういった境界はコンパイラセットの制限(*4)よりも複雑であるかもしれず、Scala コンパイラは最小の上限境界あるいは最大の下限境界として指定された型をもつ項 (term)を拒絶する自由を持ちます。

(*4) 現在の Scala コンパイラは、そのような境界中のパラメータ化のネストレベルを、 オペランド型の最大ネストレベルよりせいぜい 2 つまで深いと制限しています。

The least upper bound or greatest lower bound might also not be unique. For instance A with B and B with A are both greatest lower of A and B. If there are several least upper bounds or greatest lower bounds, the Scala compiler is free to pick any one of them.

最小の上限境界あるいは最大の下限境界は、同様にただ一つとは限りません。 例えば、A with B と B with A は、両方とも A および B の最大の下限境界です。 もし最小の上限境界あるいは最大の下限境界が複数あるときは、 Scala コンパイラはそれらの 1 つを勝手に選びます。



3.5.3 弱い適合性 (Weak Conformance)

In some situations Scala uses a more genral conformance relation. A type S weakly conforms to a type T , written S <:w T , if S <: T or both S and T are primitive number types and S precedes T in the following ordering.

Scalaはいくつかの状況では、より一般的な適合性関係を用います。 もし S <: T であるか、あるいは、S と T 両方がプリミティブな数値型で、 次の順序中で S が T の前にあるなら、 型 S は型 T に 弱く適合する といい、S <:w T と書きます。

   Byte <:w Short
   Short <:w Int
   Char <:w Int
   Int <:w Long
   Long <:w Float
   Float <:w Double

A weak least upper bound is a least upper bound with respect to weak conformance.

弱い最小の上限境界(weak least upper bound) とは、 弱い適合性に関する最小の上限境界です。



3.6 volatile 型 (Volatile Types)

Type volatility approximates the possibility that a type parameter or abstract type instance of a type does not have any non-null values. As explained in (§3.1), a value member of a volatile type cannot appear in a path.

型の揮発性(volatility)は、 型の抽象型インスタンスあるいは型パラメータがいかなる非 null 値も持たない可能性を近似します。 (§3.1)で説明したように、 volatile 型の値メンバーはパス中に現れることはできません。

もし型が 4 つのカテゴリの 1 つにあてはまるなら、 型は volatile です:

A compound type T1 with ... with Tn {R} is volatile if one of the following two conditions hold.

  1. One of T2,...,Tn is a type parameter or abstract type, or
  2. T1 is an abstract type and and either the refinement R or a type Tj for j > 1 contributes an abstract member to the compound type, or
  3. one of T1,...,Tn is a singleton type.

複合型 T1 with ... with Tn {R} は、もし次の 2 つの(訳注: 3 つの誤記?) 条件のうちの 1 つを満たすなら、volatile です。

  1. T2,...,Tn の1つが型パラメータあるいは抽象型である。あるいは、
  2. T1 が抽象型で、細別 R あるいは型 Tj ( j > 1 )が、複合型に抽象メンバを提供している。あるいは
  3. T1,...,Tn の 1 つがシングルトン型である。

Here, a type S contributes an abstract member to a type T if S contains an abstract member that is also a member of T . A refinement R contributes an abstract member to a type T if R contains an abstract declaration which is also a member of T .

ここで、もし型 S が型 T のメンバーでもあるような抽象メンバを含むなら、 型 S は型 T に 抽象メンバを提供する といいます。 もし細別 R が型 T のメンバーでもあるような抽象宣言を含むなら、 細別 R は型 T に抽象メンバを提供するといいます。

A type designator is volatile if it is an alias of a volatile type, or if it designates a type parameter or abstract type that has a volatile type as its upper bound.

A singleton type p.type is volatile, if the underlying type of path p is volatile.

An existential type T forSome { Q } is volatile if T is volatile.

もし型指定子が volatile 型のエイリアスであるか、あるいは、 もし型指定子がその上限境界として volatile 型を持つ型パラメータあるいは抽象型を指定するなら、 その型指定子は volatile です。

もしパス p の基礎をなしている型が volatile なら、シングルトン型 p.type は volatile です。

存在型 T forSome { Q } は、もし T が volatile なら、volatile です。



3.7 型消去 (Type Erasure)

型は、もしそれが型引数あるいは型変数を含むなら、 ジェネリック である言われます。 型消去(Type erasure) は、(ジェネリックでもよい)型から 非ジェネリックな型へのマッピングです。 T の型消去を |T| と書きます。 型消去のマッピングは次のように定義されます。

  • The erasure of an alias type is the erasure of its right-hand side.
  • The erasure of an abstract type is the erasure of its upper bound.
  • The erasure of the parameterized type scala.Array[T1] is scala.Array[|T1|].
  • The erasure of every other parameterized type T[T1,...,Tn] is |T|.
  • エイリアス型の型消去は、その右側の型消去。
  • 抽象型の型消去は、その上限境界の型消去。
  • パラメータ化された型 scala.Array[T1] の型消去は、scala.Array[|T1|]。
  • 他のすべてのパラメータ化された型 T[T1,...,Tn] の型消去は、|T|。
  • The erasure of a singleton type p.type is the erasure of the type of p.
  • The erasure of a type projection T#x is |T|#x.
  • The erasure of a compound type T1 with ... with Tn {R} is the erasure of the intersection dominator of T1,...,Tn .
  • The erasure of an existential type T forSome { Q } is |T|.
  • シングルトン型 p.type の型消去は、p の型消去。
  • 型射影 T#x の型消去は、|T|#x。
  • 複合型 T1 with ... with Tn {R} の型消去は、T1,...,Tn の 論理積ドミネータ (intersection dominator)の型消去。
  • 存在型 T forSome { Q } の型消去は、|T|。

The intersection dominator of a list of types T1,...,Tn is computed as follows. Ti1,...,Tim be the subsequence of types Ti which are not supertypes of some other type Tj . If this subsequence contains a type designator Tc that refers to a class which is not a trait, the intersection dominator is Tc . Otherwise, the intersection dominator is the first element of the subsequence, Ti1 .

型のリスト T1,...,Tn の 論理積ドミネータ(intersection dominator) は、 次のように計算されます。 まず、Ti1,...,Tim を型 Ti の部分列、ただし Ti は他のある型 Tj のスーパー型ではないようなものとします。 もしこの部分列がトレイトではないクラスを参照する型指定子 Tc を含むなら、 論理積ドミネータは Tc です。 そうでなければ、論理積ドミネータは、部分列の最初の要素 Ti1 です。

タグ:

+ タグ編集
  • タグ:

このサイトはreCAPTCHAによって保護されており、Googleの プライバシーポリシー利用規約 が適用されます。

最終更新:2011年02月23日 18:30
ツールボックス

下から選んでください:

新しいページを作成する
ヘルプ / FAQ もご覧ください。