Spec2.8Chap6a

第 6 章 式 (Expressions)

構文:

   Expr          ::=   (Bindings | id | '_') '=>' Expr
                   |   Expr1
   Expr1         ::=   'if' '(' Expr ')' {nl} Expr [[semi] else Expr]
                   |   'while' '(' Expr ')' {nl} Expr
                   |   'try' '{' Block '}' ['catch' '{' CaseClauses '}']
                        ['finally' Expr]
                   |    'do' Expr [semi] 'while' '(' Expr ')'
                   |    'for' ('(' Enumerators ')' | '{' Enumerators '}')
                       {nl} ['yield'] Expr
                   |   'throw' Expr
                   |   'return' [Expr]
                   |   [SimpleExpr '.'] id '=' Expr
                   |   SimpleExpr1 ArgumentExprs '=' Expr
                   |   PostfixExpr
                   |   PostfixExpr Ascription
                   |   PostfixExpr 'match' '{' CaseClauses '}'
   PostfixExpr   ::=   InfixExpr [id [nl]]
   InfixExpr     ::=   PrefixExpr
                   |   InfixExpr id [nl] InfixExpr
   PrefixExpr    ::=   ['-' | '+' | '~' | '!'] SimpleExpr
   SimpleExpr    ::=   'new' (ClassTemplate | TemplateBody)
                   |   BlockExpr
                   |   SimpleExpr1 ['_']
   SimpleExpr1   ::=   Literal
                   |   Path
                   |   '_'
                   |   '(' [Exprs] ')'
                   |   SimpleExpr '.' id s
                   |   SimpleExpr TypeArgs
                   |   SimpleExpr1 ArgumentExprs
                   |   XmlExpr
   
   Exprs         ::=   Expr {',' Expr}
   BlockExpr     ::=   '{' CaseClauses '}'
                   |   '{' Block '}'
   Block         ::=   {BlockStat semi} [ResultExpr]
   ResultExpr    ::=   Expr1
                   |   (Bindings | (id | '_') ':' CompoundType) '=>' Block
   Ascription    ::=   ':' InfixType
                   |   ':' Annotation {Annotation}
                   |   ':' '_' '*'

式は演算子とオペランドから構成されます。 式の形については、後で、優先順位の低い順に論じます。



6.1 式の型付け (Expression Typing)

The typing of expressions is often relative to some expected type (which might be undefined). When we write "expression e is expected to conform to type T ", we mean: (1) the expected type of e is T , and (2) the type of expression e must conform to T .

式の型付けは、何らかの(未定義かもしれない) 要請型(expected type) にしばしば関係します。 「式 e は型 T に適合することが要請される」と書くとき、 次を意味します: (1) e の要請型は T であり、(2) 式 e の型は T に適合しなくてはならない。

The following skolemization rule is applied universally for every expression: If the type of an expression would be an existential type T , then the type of the expression is assumed instead to be a skolemization (§3.2.10) of T .

Skolemization is reversed by type packing. Assume an expression e of type T and let t1[tps1] >: L1 <: U1,...,tn[tpsn] >: Ln <: Un be all the type variables created by skolemization of some part of e which are free in T . Then the packed type of e is

次の skolemization 規則は、すべての式に広く適用されます。: すなわち、もし式の型が存在型 T なら、式の型は代わりに T の skolemization (§3.2.10)であると仮定されます。

Skolemization は型パッキングによって逆にされます。 型 T の式 e があって、t1[tps1] >: L1 <: U1,...,tn[tpsn] >: Ln <: Un は、 T 中で自由な e のある部分の skolemization によって生成されたすべての型変数であると仮定します。 このとき e の パックされた型 は次です。

   T forSome { type t1[tps1] >: L1 <: U1 ; ...; type tn[tpsn] >: Ln <: Un }



6.2 リテラル (Literals)

構文:

   SimpleExpr  ::=   Literal

リテラル(§1.3) の型付けで記述されています。それらは直ちに評価されます。



6.3 null 値 (The Null Value)

null値は scala.Null 型であり、従って、全ての参照型と互換です。 これは特別な "null" オブジェクトを参照する参照値を表します。 このオブジェクトは、クラス scala.AnyRef 中で次のメソッドを実装します。:

  • eq(x) と == (x) は、もし引数 x も同じく "null" オブジェクトである時、かつそのときに限り true を返します。
  • ne(x) and !=(x) return true iff the argument x is not also the "null" object.
  • ne(x) と !=(x) は、もし引数 x が "null" オブジェクトでない時、かつそのときに限り true を返します。
  • isInstanceOf[T] は、常に false を返します。
  • asInstanceOf[T] は、もし T が scala.AnyRef に適合するなら "null" オブジェクトそれ自身を返し、そうでなければ NullPointerException を送出します。

"null" オブジェクトの他のメンバーへの参照は、すべて NullPointerException 送出を引き起こします。



6.4 指定子 (Designators)

構文:

   SimpleExpr   ::=   Path
                  |   SimpleExpr '.' id

A designator refers to a named term.

It can be a simple name or a selection. A simple name x refers to a value as specified in §2. If x is bound by a definition or declaration in an enclosing class or object C , it is taken to be equivalent to the selection C.this.x , where C is taken to refer to the class containing x even if the type name C is shadowed (§2) at the occurrence of x .

指定子は、名前付きの項(named term)を参照します。

それは 単純名 または 選択(selection) です。 単純名 x は、 §2 中で定めた値を参照します。 もし x が取り囲むクラス/オブジェクト C 中の定義/宣言によって束縛されるなら、 それは、選択 C.this.x と等価であるとみなされます。 ここで C は、たとえ型名 C が x の出現時に隠されていても (§2)、 x を含むクラスを参照するとみなされます。

If r is a stable identifier (§3.1) of type T , the selection r.x refers statically to a term member m of r that is identified in T by the name x .

For other expressions e, e.x is typed as if it was { val y = e ; y.x }, for some fresh name y .

もし r が型 T の安定識別子 (§3.1)なら、 選択 r.x は、T において名前 x と同一視される、 r の項メンバー m を静的に参照します。

他の式 e については、 e.x はそれが { val y = e ; y.x } (y は、ある新規の名前)であるかのように、型付けされます。

The expected type of a designator's prefix is always undefined. The type of a designator is the type T of the entity it refers to, with the following exception: The type of a path (§3.1) p which occurs in a context , where a stable type (§3.2.1) is required , is the singleton type p.type .

指定子の前置子の要請型は、常に未定義です。 指定子の型は、それが参照するエンティティの型 T ですが、次の例外があります: 安定型(§3.2.1) が要求されるコンテキスト中に現れるパス (§3.1) p の型は、 シングルトン型 p.type です。

The contexts , where a stable type is required , are those that satisfy one of the following conditions:

  1. The path p occurs as the prefix of a selection and it does not designate a constant , or
  2. The expected type pt is a stable type, or
  3. The expected type pt is an abstract type with a stable type as lower bound, and the type T of the entity referred to by p does not conform to pt, or
  4. The path p designates a module .

安定型が要求されるコンテキストは、次の条件の 1 つを満たすものです。:

  1. パス p は選択の前置子として出現し、定数を指定しない。あるいは
  2. 要請型 pt は安定型である。あるいは
  3. 要請型 pt は下限境界に安定型をもつ抽象型で、p によって参照されるエンティティの型 T が pt に適合しない。あるいは
  4. パス p はモジュールを指定する。

The selection e.x is evaluated by first evaluating the qualifier expression e, which yields an object r , say. The selection's result is then the member of r that is either defined by m or defined by a definition overriding m. If that member has a type which conforms to scala.NotNull, the member's value must be initialized to a value different from null, otherwise a scala.UnitializedError is thrown .

選択 e.x の評価では、はじめに限定修飾している式 e を評価します。 それは例えば、オブジェクト r をもたらします。 選択の結果は、m によって定義されているか、あるいは m をオーバーライドする 定義によって定義されている、r のメンバーです。 もしそのようなメンバーが scala.NotNull に適合する型を持っていれば、 メンバーの値は null と異なる値に初期化されなくてはなりません。 そうでなければ scala.UnitializedError が送出されます。



6.5 this と super (This and Super)

構文:

   SimpleExpr   ::=   [id '.'] 'this'
                  |   [id '.'] 'super' [ClassQualifier] '.' id

The expression this can appear in the statement part of a template or compound type.It stands for the object being defined by the innermost template or compound type enclosing the reference. If this is a compound type, the type of this is that compound type. If it is a template of a class or object definition with simple name C , the type of this is the same as the type of C.this .

式 this は、テンプレートあるいは複合型の文部分中に現われます。 それは、参照を囲む最も内側のテンプレートあるいは複合型によって 定義されているオブジェクトを表します。 もしそれが複合型なら、this の型はその複合型です。 もしそれが単純名 C をもつクラス/オブジェクト定義のテンプレートなら、 this の型は C.this の型と同じです。

The expression C.this is legal in the statement part of an enclosing class or object definition with simple name C . It stands for the object being defined by the innermost such definition. If the expression's expected type is a stable type, or C.this occurs as the prefix of a selection, its type is C.this.type, otherwise it is the self type of class C .

式 C.this は、単純名 C をもつ取り囲むクラス/オブジェクト定義の文部分内では、 正しいです。 これは、最も内側のそのような定義によって定義されつつあるオブジェクトを 表します。 もし、式の要請型が安定型であるか、あるいは C.this が選択の 前置子として現れるなら、その型は C.this.type であり、そうでなければ クラス C の自己型です。

A reference super.m refers statically to a method or type m in the least proper supertype of the innermost template containing the reference. It evaluates to the member m´ in the actual supertype of that template which is equal to m or which overrides m. The statically referenced member m must be a type or a method. If it is a method, it must be concrete, or the template containing the reference must have a member m´ which overrides m and which is labeled abstract override .

参照 super.m は、参照を含む最も内側のテンプレートの最小固有のスーパー型中の、 メソッドあるいは型 m を静的に参照します。 それは、m に等しいかあるいは m をオーバライドする、 そのテンプレートの実際のスーパー型中のメンバー m´へ評価されます。 静的に参照されるメンバー m は、型あるいはメソッドでなければなりません。 もしそれがメソッドなら、それは具象であるか、あるいは、 その参照を含むテンプレートが m をオーバライドする abstract override と印されたメンバー m´を持たなくてはなりません。

A reference C.super.m refers statically to a method or type m in the least proper supertype of the innermost enclosing class or object definition named C which encloses the reference. It evaluates to the member m´ in the actual supertype of that class or object which is equal to m or which overrides m. The statically referenced member m must be a type or a method. If the statically referenced member m is a method, it must be concrete, or the innermost enclosing class or object definition named C must have a member m´ which overrides m and which is labeled abstract override .

参照 C.super.m は、その参照を囲む、最も内側の取り囲む C と名付けられたクラス/オブジェクト定義の最小固有のスーパー型中の、 メソッドあるいは型 m を静的に参照します。 それは、m に等しいかあるいは m をオーバライドする、 そのクラス/オブジェクトの実際のスーパー型中のメンバー m´へ評価されます。 静的に参照されるメンバー m は、型あるいはメソッドでなければなりません。 もし静的に参照されるメンバー m がメソッドなら、それは具象であるか、あるいは、 最も内側の取り囲む C と名付けられたクラス/オブジェクト定義が、 m をオーバライドする abstract override と印されたメンバー m´ を持たなくてはなりません。

The super prefix may be followed by a trait qualifier [T], as in C.super[T].x. This is called a static super reference. In this case, the reference is to the type or method of x in the parent trait of C whose simple name is T . That member must be uniquely defined. If it is a method, it must be concrete.

super 前置子の後には、C.super[T].x のように、 トレイト限定修飾子 [T] が続くことがあります。 これは、 静的 super 参照(static super reference) と呼ばれます。 この場合、参照は、その単純名が T である C の、 親トレイト中の型あるいはメソッド x への参照です。 そのようなメンバーはユニークに定義されていなければなりません。 もしそれがメソッドなら、具象でなければなりません。


Example 6.5.1 : 次のクラス定義について考えます。

   class Root { def x = "Root" }
   class A extends Root { override def x = "A" ; def superA = super.x }
   trait B extends Root { override def x = "B" ; def superB = super.x }
   class C extends Root with B {
     override def x = "C" ; def superC = super.x
   }
   class D extends A with B {
     override def x = "D" ; def superD = super.x
   }

クラス C の線形化は {C, B, Root} であり、クラス D の線形化は {D, B, A, Root} です。 このとき次を得ます。

   (new A).superA == "Root",
                             (new C).superB = "Root", (new C).superC = "B",
   (new D).superA == "Root", (new D).superB = "A",    (new D).superD = "B",

B がクラス Root あるいは A のどちらとミックスインされるかによって、 superB 関数が異なる結果を返すことに注意してください。

(訳注:この例について(他の例も含め)、訳者は確認していません)



6.6 関数適用 (Function Applications)

構文:

   SimpleExpr    ::=  SimpleExpr1 ArgumentExprs
   ArgumentExprs ::=  '(' [Exprs] ')'
                   |  '(' [Exprs ','] PostfixExpr ':' '_' '*' ')'
                   |  [nl] BlockExpr
   Exprs         ::=  Expr {',' Expr}

An application f(e1,...,em) applies the function f to the argument expressions e1,...,em . If f has a method type (p1 :T1,...,pn :Tn)U , the type of each argument expression ei is typed with the corresponding parameter type Ti as expected type . Let Si be type type of argument ei (i = 1,...,m). If f is a polymorphic method, local type inference (§6.26.4) is used to determine type arguments for f . If f has some value type, the application is taken to be equivalent to f.apply(e1,...,em), i.e. the application of an apply method defined by f .

The function f must be applicable to its arguments e1,...,en of types S1,...,Sn .

適用 f(e1,...,em)は、関数 f を引数式 e1,...,em に適用します。 もし f がメソッド型 (p1 :T1,...,pn :Tn)U をもつなら、各引数式 ei の型は、 対応するパラメータ型 Ti を要請型として型付けされます。 Si を引数 ei (i = 1,...,m)の型であるとします。 もし f が多相的メソッドなら、f の型引数の決定にローカルな型推論 (§6.26.4) が使われます。 もし f が何らかの値型を持っていれば、その適用は f.apply(e1,...,em)、 すなわち、f で定義された apply メソッドの適用とみなされます。

関数 f は、型 S1,...,Sn の引数 e1,...,en に 適用可能 でなければなりません。

If f has a method type (p1 : T1,...,pn : Tn)U we say that an argument expression ei is a named argument if it has the form xi = e´i and xi is one of the parameter names p1,...,pn . The function f is applicable if all of the follwing conditions hold:

もし f がメソッド型 (p1 : T1,...,pn : Tn)U を持ち、引数式 ei が xi = e´i の形 (xi はパラメータ名 p1,...,pn の 1 つ)なら、 引数式 ei を 名前付き 引数と言います。 もし次の条件がすべて満たされるなら、関数 f は適用可能です:

  • For every named argument xi = e´i , the type Si is compatible with the parameter type Tj whose name pj matches xi .
  • For every positional argument ei , the type Si is compatible with Ti .
  • If the expected type is defined, the result type U is compatible to it .
  • すべての名前付き引数 xi = e´i について、型 Si は、xi にマッチする名前 pj のパラメータ型 Tjと互換である。
  • すべての位置的な(positional)引数 ei について、型 Si は Ti と互換である。
  • もし要請型が定義されているなら、結果型 U はそれに互換である。

If f is a polymorphic method it is applicable if local type inference (§6.26.4) can determine type arguments so that the instantiated method is applicable. If f has some value type it is applicable if it has a method member named apply which is applicable .

もし f が多相的メソッドで、 もしインスタンス化されたメソッドが適用可能であるようにローカルな型推論 (§6.26.4)が型引数を決定できるなら、 f は適用可能です。 もし f が何らかの値型を持ち、 apply と名付けられた適用可能なメソッドメンバーをもつなら、 f は適用可能です。

Evaluation of f(e1,...,en) usually entails evaluation of f and e1,...,en in that order . Each argument expression is converted to the type of its corresponding formal parameter. After that, the application is rewritten to the function's right hand side, with actual arguments substituted for formal parameters. The result of evaluating the rewritten right-hand side is finally converted to the function's declared result type, if one is given .

f(e1,...,en)の評価は通常、f と e1,...,en のこの順番での評価を必要とします。 各引数式は、その対応する形式上のパラメータの型に変換されます。 そのあと、その適用は、形式上のパラメータの代わりに実際の引数を用いて、 関数の右側へ書き直されます。 書き直された右側の評価結果は、最終的に関数の宣言された結果型へ、 もし与えられていれば、変換されます。

The case of a formal parameter with a parameterless method type =>T is treated specially. In this case, the corresponding actual argument expression e is not evaluated before the application. Instead, every use of the formal parameter on the right-hand side of the rewrite rule entails a re-evaluation of e. In other words, the evaluation order for =>-parameters is call-by-name whereas the evaluation order for normal parameters is call-by-value. Furthermore, it is required that e's packed type (§6.1) conforms to the parameter type T . The behavior of by-name parameters is preserved if the application is transformed into a block due to named or default arguments. In this case, the local value for that parameter has the form val yi = () => e and the argument passed to the function is yi() .

パラメータなしのメソッド型 =>T をもつ形式上のパラメータの場合は、 特別に扱われます。 この場合、対応する実際の引数式 e は適用の前には評価されません。 代わりに、形式上のパラメータを使用する度に、書き直し規則の右側で e の再評価が必要となります。 言い替えれば、=>-パラメータ の評価規則は 名前呼出し であり、他方、 標準的なパラメータの評価規則は 値呼出し です。 さらに、e のパックされた型(§6.1)は、 パラメータ型 T に適合することが要求されます。 名前呼び出しパラメータの動作は、 もし適用が名前付き/デフォルト引数に起因してブロックに変換されるなら、維持されます。 この場合、パラメータのローカルな値は val yi = () => e の形であり、 関数に渡される引数は yi() です。

The last argument in an application may be marked as a sequence argument, e.g. e : _*. Such an argument must correspond to a repeated parameter (§4.6.2) of type S * and it must be the only argument matching this parameter (i.e. the number of formal parameters and actual arguments must be the same). Furthermore, the type of e must conform to scala.Seq[T], for some type T which conforms to S. In this case, the argument list is transformed by replacing the sequence e with its elements. When the application uses named arguments, the vararg parameter has to be specified exactly once.

適用における最後の引数は、シーケンス引数と印されているかもしれません。 たとえば e : _* です。 そのような引数は、型 S* の反復パラメータ (§4.6.2) に対応していなければならず、 そしてこのパラメータと一致する唯一の引数でなければなりません (すなわち、形式上のパラメータ数と実際の引数の数が同じでなければなりません)。 さらに、e の型は、S に適合する何らかの型 T があって、 scala.Seq[T] に適合しなくてはなりません。 この場合、引数リストは、シーケンス e をその要素で置き換えて変換されます。 適用が名前付き引数を使うときは、 可変引数(vararg)パラメータは正確にただ 1 度だけ指定されなければなりません。

関数適用は通常、 プログラムのランタイムスタック上に新しいフレームを割り当てます。 しかし、もしローカル関数あるいは final メソッドがそれ自身を最後の動作として呼び出すなら、 その呼び出しは呼び出す側のスタックフレームを使って実行されます。


Example 6.6.1 : 引数の変数の合計を数える次の関数を仮定します:

   def sum(xs: Int*) = (0 /: xs) ((x, y) => x + y)

このとき

   sum(1, 2, 3, 4)
   sum(List(1, 2, 3, 4): _*)

の両方とも、10 という結果をもたらします。

他方、

   sum(List(1, 2, 3, 4))

は、型チェックを通らないでしょう。



6.6.1 名前付き引数とデフォルト引数 (Named and Default Arguments)

If an application might uses named arguments p = e or default arguments, the following conditions must hold .

  • The named arguments form a suffix of the argument list e1,...,em , i.e. no positional argument follows a named one .
  • The names xi of all named arguments are pairwise distinct and no named argument defines a parameter which is already specified by a positional argument .
  • Every formal parameter pj : Tj which is not specified by either a positional or a named argument has a default argument .

もし適用が、名前付き引数 p = e あるいはデフォルト引数を使うなら、 次の条件を満たさなくてはなりません。

  • 名前付き引数が引数リスト e1,...,em の接尾部を形成する、つまり、いかなる位置的な引数も名前付き引数の後には続かない。
  • すべての名前付き引数の名前 xi は対として異なり、いかなる名前付き引数も、位置的引数によって既に指定されたパラメータを定義しない。
  • 位置的あるいは名前付き引数のいずれにも指定されていない、すべての形式上のパラメータ pj : Tj は、デフォルト引数を持つ。

If the application uses named or default arguments the following transformation is applied to convert it into an application without named or default arguments . The result of transforming f is a block of the form

もし適用が名前付き/デフォルト引数を使うなら、次の変形が、 それを名前付き/デフォルト引数のない適用へ変えます。 もし関数 f が p.m[targs] の形なら、それは次のようなブロックに変換されます。

   { val q = p
     q.m[targs]
   }

If the function f is itself an application expression the transformation is applied recursively on f .

もし関数 f がそれ自身適用式なら、変形は f に再帰的に適用されます。

f の変形結果は、次の形のブロックです

   { val q = p
     val x1 = expr1
       ...
       val xk = exprk
       q.m[targs](args1),..., (argsl)
   }

where every argument in (args1),..., (argsl) is a reference to one of the values x1,...,xk . To integrate the current application into the block, first a value definition using a fresh name yi is created for every argument in e1,...,em , which is initialised to ei for positional arguments and to e´i for named arguments of the form xi = e´i .Then, for every parameter which is not specified by the argument list, a value definition using a fresh name zi is created, which is initialized using the method computing the default argument of this parameter (§4.6) .

ここで、(args1),..., (argsl)中の各引数は、値 x1,...,xk の 1 つへの参照です。 現在の適用をブロックへまとめるために、 はじめに、 e1,...,em 中の各引数に対して新規の名前 yi を使った値定義が生成されます。 位置的引数は ei へ初期化され、xi = e´i の形の名前付き引数は e´i へ初期化されます。 つぎに、引数リストで指定されてないすべてのパラメータについては、 新規の名前 zi を使った値定義が生成されます。それは、 このパラメータのデフォルト引数を計算するメソッドを使って初期化されます (§4.6)。

Let args be a permutation of the generated names yi and zi such such that the position of each name matches the position of its corresponding parameter in the method type (p1 : T1,...,pn : Tn)U . The final result of the transformation is a block of the form

args を生成された名前 yi と zi の置換(permutation)で、 各名前の位置がメソッド型 (p1 : T1,...,pn : Tn)U 中の対応するパラメータ位置にマッチするものとします。 変形の最終結果は、次の形のブロックです

   { val q = p
     val x1 = expr1
     ...
     val xl = exprk
     val y1 = e1
     ...
     val ym = em
     val z1 = q.m$default$i[targs](args1),..., (argsl)
     ...
     val zd = q.m$default$j[targs](args1),..., (argsl)
     q.m[targs](args1),..., (argsl)(args)
   }



6.7 メソッド値 (Method Values)

構文:

   SimpleExpr        ::=   SimpleExpr1 '_'

The expression e _ is well-formed if e is of method type or if e is a call-by-name parameter. If e is a method with parameters, e _ represents e converted to a function type by eta expansion (§6.26.5). If e is a parameterless method or call-by-name parameter of type =>T , e _ represents the function of type () => T , which evaluates e when it is applied to the empty parameter list () .

もし e がメソッド型であるかあるいは、もし e が名前呼び出しパラメータなら、 式 e _ は正しい形です。 もし e がパラメータをもつメソッドなら、e _ は、イータ展開 (§6.26.5) によって関数型に変換された e を表します。 もし e がパラメータなしのメソッドあるいは、型= > T の名前呼び出しパラメータなら、e _ は型() => T の関数を表し、 それが空きのパラメータリスト () に適用されたときに e を評価します。


Example 6.7.1 : 次の左カラム中のメソッド値は、それぞれ右の無名関数 (link_anchor plugin error : 画像もしくは文字列を必ずどちらかを入力してください。に等価です。

   Math.sin _                 x =>Math.sin(x)
   Array.range _              (x1,x2) => Array.range(x1, x2)
   List.map2 _                (x1,x2) => (x3) => List.map2(x1, x2)(x3)
   List.map2(xs, ys)_         x =>List.map2(xs, ys)(x)

メソッド名とお終いの下線の間に空白が必要であることに注意してください なぜなら、そうでなければ下線は名前の一部とみなされるからです。



6.8 型適用 (Type Applications)

構文:

   SimpleExpr        ::=    SimpleExpr TypeArgs

A type application e[T1,...,Tn] instantiates a polymorphic value e of type [a1 >: L1 <: U1,...,an >: Ln <: Un]S with argument types T1,...,Tn . Every argument type Ti must obey the corresponding bounds Li and Ui . That is, for each i = 1,...,n, we must have σLi <: Ti <: σUi , where σ is the substitution [a1 := T1,...,an := Tn]. The type of the application is σS .

型適用 e[T1,...,Tn] は、引数型 T1,...,Tn をもつ型 [a1 >: L1 <: U1,...,an >: Ln <: Un]S の多相的な値 e をインスタンス化します。 すべての引数型 Ti は、対応する上下限境界 Li と Ui に従わなくてはなりません。 すなわち、各 i = 1,...,n に対し σLi <: Ti <: σUi でなければなりません。 ここで σは置換 [a1: = T1,...,an:= Tn] です。 適用の型は σS です。

If the function part e is of some value type, the type application is taken to be equivalent to e.apply[T1,...,Tn], i.e. the application of an apply method defined by e .

もし関数部 e が何らかの値型なら、型適用は e.apply[T1,...,Tn] と同じとされます。すなわち、e によって定義された apply メソッドの適用です。

Type applications can be omitted if local type inference (§6.26.4) can infer best type parameters for a polymorphic functions from the types of the actual function arguments and the expected result type .

多相的な関数に対し、もしローカルな型推論 (§6.26.4) が実際の関数引数の型と要請される結果型から最も良い型パラメータを推論できる場合は、 型適用は省略できます。



6.9 タプル (Tuples)

構文:

   SimpleExpr    ::=       '(' [Exprs] ')'

A tuple expression (e1,...,en) is an alias for the class instance creation scala.Tuplen(e1,...,en) , where n >= 2. The empty tuple () is the unique value of type scala.Unit .

タプル式 (e1,...,en) は、クラスインスタンス生成 scala.Tuplen(e1,...,en)の エイリアスです。ここで、n >= 2 。 空タプル () は、型 scala.Unit のただ 1 つの値です。

タグ:

+ タグ編集
  • タグ:

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

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

下から選んでください:

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