Featherweight Scalaの紹介および型付け規則の決定性について          @mzp
元論文“A Core Calculus for Scala Type Checking” - Vincent Cremet, François Garillot, SergueïLenglet, Martin OderskyProceeding...
今日やること1. Featherweight Sacalの文法・評価ルールの 定義2. 型付け規則の定義3. 型付け規則の決定可能性を証明      決定可能性 := 決定的アルゴリズム + 停止性
val list12 = new Cons { this0 |         type Elem = Nat         val hd : Nat = zero.succ()Featherweight Scala         val ...
}          Scalaとの違いThe List example showed how genericity can be ethere is a general encoding that lets one encode allint...
type Elem              traitは継承できるtrait List extends Any { this0 |   type ListOfElem = List { this1 | type Elem = this0.El...
syntactic sugar so this is done automatically whenever a first-class function valuin function position in an application). ...
Featherweight Scalaの       定義
文法定義Syntaxx, y, z,                      Variablea                              Value label           p ::=                ...
val x = new T ; t              Objeceductionルールの読み方  valn a : T = t 2 ⌃(x)                             (red-value     ⌃ ; ...
val x = new T ; t              Objeceductionルールの読み方  valn a : T = t 2 ⌃(x)                             (red-value     ⌃ ; ...
val x = new T ; t              Objeceductionルールの読み方  valn a : T = t 2 ⌃(x) ←ルールを適用する前提                             (red-va...
val x = new T ; t              Objeceductionルールの読み方  valn a : T = t 2 ⌃(x) ←ルールを適用する前提                             (red-va...
val x = new T ; t              Objeceductionルールの読み方  valn a : T = t 2 ⌃(x) ←ルールを適用する前提                             (red-va...
val x = new T ; t              Objeceductionルールの読み方                  ↓xが...  valn a : T = t 2 ⌃(x) ←ルールを適用する前提            ...
val x = new T ; t              Objeceductionルールの読み方   ↓val a:T = tと定   義されている         ↓xが...  valn a : T = t 2 ⌃(x) ←ルールを適...
val x = new T ; t               Objeceductionルールの読み方   ↓val a:T = tと定   義されている          ↓xが...  valn a : T = t 2 ⌃(x) ←ルール...
T |M          Term traitn A extends = t 2 ⌃(x)         Class decl                           valn a : T                    ...
(red-method)  ⌃ ; x.a(y) ! ⌃ ; declarations, but we have to check that⌃ 0 ; declaration we are         collect its [y/z]t ...
Path Typing                        型付け規則                   x:T 2                          S,       ` p.type 3 valn a : T (...
各記号の意味 The first two boxes of Figure 6 pr judgment S, ` t : T always ass path 式を記録する receives the type p.t       p always  ...
パスの型付けPath Typing                   x:T 2                        S,   ` p.type 3 valn a : T (= t)?                        ...
( -type)         (S, S,` T`wf)  N                        p.A?                                 S, x.A ` `T ´ ˘ | M ¯ wf    ...
Well-FormednessWell-Formedness                                                                  ` ´˘    ¯ ` ´˘     ¯      ...
Well-Formdness for Well-Formedness                                                                    ` ´˘    ¯ ` ´˘     ¯...
` ´˘     ¯      S, ` p.type 3 typen A = T                                S,    ` p.type 3 traitn A extends T  | M      {n}...
S,    `⇤ p.type <: q.type                          S, ` Ti <: p.A                         (<:-singleton-right)            ...
証明しましょうこの型付け規則が決定的かつ停止することを示す
決定性の証明命題 この計算は決定的アルゴリズムである 文法と型付け規則が一対一対応するた め、自明     「決定的 = 常に同じ遷移をする」
型付け規則の停止性命題          型付け規則が停止する•   基本: 規則に関する帰納法で証明する•   Sに関する帰納法を使う•   式のサイズ(textual size)が減少することで示す        帰納法で示せないケースは別...
サブタイプ関係の停止性命題     サブタイプの判定は停止する• 基本: 規則に関する帰納法で証明する• プログラムサイズが有限のため停止する• 背理法を使う     帰納法で示せないケースは別の尺度で停止性を示     すよ
well-formedの停止性命題     well-formedかの判定は停止する• 基本: 規則に関する帰納法で証明する• 背理法を使う     前のやつと同じ
full-Scalaとの違い•   Featherweight Scalaの結論をFull Scalaに適用できるか•   いくつか違いがあるのでそのままの適用は無理    •   最大の違い: local type inference•   ...
まとめ
まとめFeatherweight Scalaのtype checkingが決定可能であることを証明しました。
Upcoming SlideShare
Loading in …5
×

Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について

1,888 views

Published on

タイトルまちがえた..。決定性→決定可能性です。

Published in: Technology
0 Comments
3 Likes
Statistics
Notes
  • Be the first to comment

No Downloads
Views
Total views
1,888
On SlideShare
0
From Embeds
0
Number of Embeds
189
Actions
Shares
0
Downloads
6
Comments
0
Likes
3
Embeds 0
No embeds

No notes for slide
  • \n
  • &amp;#x30EB;&amp;#x30FC;&amp;#x30EB;&amp;#x304C;&amp;#x304A;&amp;#x304A;&amp;#x3044;&amp;#x306E;&amp;#x3067;&amp;#x30C0;&amp;#x30A6;&amp;#x30F3;&amp;#x30ED;&amp;#x30FC;&amp;#x30C9;&amp;#x3057;&amp;#x3068;&amp;#x3044;&amp;#x3066;&amp;#x306D;&amp;#x3002;\nScalaBase&amp;#x306E;&amp;#x52DF;&amp;#x96C6;&amp;#x30DA;&amp;#x30FC;&amp;#x30B8;&amp;#x304B;&amp;#x3089;&amp;#x843D;&amp;#x305B;&amp;#x307E;&amp;#x3059;&amp;#x3002;\n
  • \n
  • \n
  • class&amp;#x304C;&amp;#x306A;&amp;#x3044;&amp;#x3002;trait&amp;#x306E;&amp;#x307F;\n&amp;#x30E1;&amp;#x30F3;&amp;#x30D0;&amp;#x3068;&amp;#x3057;&amp;#x3066;&amp;#x578B;&amp;#x3092;&amp;#x3082;&amp;#x3066;&amp;#x308B;\nthis&amp;#x3092;&amp;#x660E;&amp;#x793A;&amp;#x3059;&amp;#x308B;\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • RED-VALUE: &amp;#x5909;&amp;#x6570;&amp;#x53C2;&amp;#x7167;\nRED-METHOD: &amp;#x30E1;&amp;#x30BD;&amp;#x30C3;&amp;#x30C9;&amp;#x547C;&amp;#x3073;&amp;#x51FA;&amp;#x3057;\nRED-NEW: &amp;#x30A4;&amp;#x30F3;&amp;#x30B9;&amp;#x30BF;&amp;#x30F3;&amp;#x30B9;&amp;#x5316;\nRED-CONTEXT: &amp;#x5F15;&amp;#x6570;&amp;#x3068;&amp;#x304B;&amp;#x306E;&amp;#x547C;&amp;#x3073;&amp;#x51FA;&amp;#x3057;\n
  • &amp;#x30FB;&amp;#x8907;&amp;#x6570;&amp;#x306E;&amp;#x7D99;&amp;#x627F;&amp;#x3057;&amp;#x3066;&amp;#x308B;&amp;#x5834;&amp;#x5408;&amp;#x306F;&amp;#x3001;&amp;#x5F8C;&amp;#x306B;&amp;#x5B9A;&amp;#x7FA9;&amp;#x3055;&amp;#x308C;&amp;#x3066;&amp;#x3044;&amp;#x308B;&amp;#x30E1;&amp;#x30BD;&amp;#x30C3;&amp;#x30C9;&amp;#x304C;&amp;#x52DD;&amp;#x3064;\n
  • \n
  • \n
  • \n
  • this&amp;#x306E;&amp;#x89E3;&amp;#x6C7A;\n&amp;#x30A8;&amp;#x30A4;&amp;#x30EA;&amp;#x30A2;&amp;#x30B9;&amp;#x306E;&amp;#x89E3;&amp;#x6C7A;\n&amp;#x30AF;&amp;#x30E9;&amp;#x30B9;&amp;#x5B9A;&amp;#x7FA9;&amp;#x306E;&amp;#x5C55;&amp;#x958B;\n\n
  • &amp;#x5909;&amp;#x306A;&amp;#x518D;&amp;#x5E30;&amp;#x3092;&amp;#x3067;&amp;#x304D;&amp;#x306A;&amp;#x3044;&amp;#x3088;&amp;#x3046;&amp;#x306B;&amp;#x3059;&amp;#x308B;&amp;#x3002;\n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • \n
  • Scala基礎勉強会: Featherweight Scalaの紹介および型付け規則の決定可能性について

    1. 1. Featherweight Scalaの紹介および型付け規則の決定性について @mzp
    2. 2. 元論文“A Core Calculus for Scala Type Checking” - Vincent Cremet, François Garillot, SergueïLenglet, Martin OderskyProceedings of MFCS 06, Stará Lesná, August 2006. 細かい証明はこっちを読んでね
    3. 3. 今日やること1. Featherweight Sacalの文法・評価ルールの 定義2. 型付け規則の定義3. 型付け規則の決定可能性を証明 決定可能性 := 決定的アルゴリズム + 停止性
    4. 4. val list12 = new Cons { this0 | type Elem = Nat val hd : Nat = zero.succ()Featherweight Scala val tl : this0.ListOfElem = list2 }The List example showed how genericity can be encoded using abstract typethere is a general encoding that lets one encode all forms of parameterized typeinto types with abstract members. Details are found in [1].この論文で定義されたScalaのサブセット trait Function extends Any { this0 | type Dom type Range def apply(x : Dom): Range } val inc = new Function { this0 | type Dom = Nat type Range = Nat def apply(x : this0.Dom): this0.Range = x.succ() } Fig. 3. Definition of first-class functions Featherweight Javaに影響されてるよ
    5. 5. } Scalaとの違いThe List example showed how genericity can be ethere is a general encoding that lets one encode allinto types with abstract members. Details are foun 自分自身を差す名前を明示する trait Function extends Any { this0 | type Dom type Range コレ def apply(x : Dom): Range } val inc = new Function { this0 | type Dom = Nat outer classへのアクセス type Range = Nat def apply(x : this0.Dom): this0.Range = x.succ(
    6. 6. type Elem traitは継承できるtrait List extends Any { this0 | type ListOfElem = List { this1 | type Elem = this0.Elem } def isEmpty(): Boolean def head(): this0.Elem List extends Any { this0 | trait def tail(): this0.ListOfElem type Elem trait List extends Any { this0 |} type ListOfElem = List { this1 | Elem Elem = this0.Elem } type type def isEmpty(): Booleantrait Nil extends List { this0 | type ListOfElem = List { this1 | type Elem = th def isEmpty(): Boolean = true this0.Elem def head(): def isEmpty(): Boolean def head(): this0.Elem =tail(): this0.ListOfElem def head(): this0.Elem def error(”Nil.head”) } def tail(): this0.ListOfElem = error(”Nil.tail”) def tail(): this0.ListOfElem} } trait Nil extends List { this0 | def isEmpty(): Boolean = true extends List { this0 |trait Cons extends List { this0 | trait Nil val hd : this0.Elem def head(): this0.Elem = error(”Nil.head”) Boolean = true def isEmpty(): val tl : this0.ListOfElem tail(): this0.ListOfElem def head(): this0.Elem = error(”Nil.head”) def = error(”Nil.tail”) } def isEmpty(): Boolean = false def tail(): this0.ListOfElem = error(”Nil.tail”) def head(): this0.Elem = hd extends List { this0 | trait Cons } def tail(): this0.ListOfElem: = tl val hd this0.Elem trait Cons extends List { this0 |} val tl : this0.ListOfElem val hd : this0.Elem def isEmpty(): Boolean = false val tl : this0.ListOfElem def head(): this0.Elem = hd Fig. 2. tail(): this0.ListOfElem class hierarchyBoolean = false def Definition of the List = tl def isEmpty(): 多重継承もできるよ } def head(): this0.Elem = hd def tail(): this0.ListOfElem = tl }The element type of a given list is represented by the type member Elem of class Fig. 2. Definition of the List class hierarchy
    7. 7. syntactic sugar so this is done automatically whenever a first-class function valuin function position in an application). As an example, Figure 4 presents a map function which applies a givenメソッドに多相性はないfunction to all elements of a given list and returns a list consisting of all thethese applications. In regular Scala, this function would be defined as follows: def map[A, B](f : A ) B, xs : List[A]): List[B] = if (xs.isEmpty) Nil else f(x.head) :: map(f, xs.tail)Since map is conceptually a polymorphic method, its encoding in Featherweimakes use of a wrapper class Mapper which defines two abstract types A andtrait Mapper extends Any { this0 |sentingAthe element types of the argument and result lists, respectively. type type B map method in Mapper takes as arguments a function f from type A t Theand amap(f :xs of element Dom = A. It returns a list of element type B. An appl def list Function { type type this0.A; type Range = this0.B }, xs : List { type Elem = this0.A }): List { type Elem = this0.B } = would be written as follows:map if (xs.isEmpty()) { val result = new Nil { val list23 ==new Mapper { type A = Nat; type B = Nat }.map(inc, li type Elem this0.B };This instantiates the Mapper class with type Nat as the element type of the resultand result{ list, and invokes the map method of the instantiation with inc and } else val result = new Cons {arguments. The expression would return the encoding of the list (2, 3). type Elem = this0.B The example f.apply(xs.head()) val hd = shows that monomorphic functions such as inc can be first-claHowever, val tl = this0.map(f, xs.tail()) be generalized to polymorphic functions. T }; the construction cannotis that result polymorphic functions like map have to be encoded using wrapper claswrapper classes are first-class values neither in Featherweight nor in regular }}
    8. 8. Featherweight Scalaの 定義
    9. 9. 文法定義Syntaxx, y, z, Variablea Value label p ::= PathA Type label x Variable p.a Field selectionP ::=˘ ¯ Program x|M t S, T, U ::= Type p.A Type selection p.type ` ´˘ ¯ Singleton typeM, N ::= Member decl ? T |M Type signature valn a ` T (= t) : ´ Field decl defn a y : S : T (= t)? Method decl ? typen A (= T ) ` ´˘ ¯ Type decl traitn A extends T | M Class decls, t, u ::= Term x Variable t.a ` ´ Field selection s.a t Method call val x = new T ; t Object creationReduction valn a : T = t 2 ⌃(x) ⌃`T M BNFっぽいね x (red-value) ⌃ ; x.a ! ⌃ ; t ⌃ ; val x = new T ; t ! ⌃, x : M ; t ` ´ (red-new)defn a z : S : T = t 2 ⌃(x) (red-method) ⌃ ; x.a(y) ! ⌃ ; [y/z]t ⌃ ; t ! ⌃ 0 ; t0 (red-context) ⌃ ; e[t] ! ⌃ 0 ; e[t0 ]
    10. 10. val x = new T ; t Objeceductionルールの読み方 valn a : T = t 2 ⌃(x) (red-value ⌃ ; x.a ! ⌃ ; t ` ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    11. 11. val x = new T ; t Objeceductionルールの読み方 valn a : T = t 2 ⌃(x) (red-value ⌃ ; x.a ! ⌃ ; t ↑定義する記号 ` ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    12. 12. val x = new T ; t Objeceductionルールの読み方 valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ↑定義する記号 ` ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    13. 13. val x = new T ; t Objeceductionルールの読み方 valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ←ルールを適用した結果 ↑定義する記号 ` ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    14. 14. val x = new T ; t Objeceductionルールの読み方 valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ←ルールを適用した結果 ↑各変数の ↑定義する記号 ` binding ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    15. 15. val x = new T ; t Objeceductionルールの読み方 ↓xが... valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ←ルールを適用した結果 ↑各変数の ↑定義する記号 ` binding ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    16. 16. val x = new T ; t Objeceductionルールの読み方 ↓val a:T = tと定 義されている ↓xが... valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ←ルールを適用した結果 ↑各変数の ↑定義する記号 ` binding ´efn a z : S : T = t 2 ⌃(x) (red-method ⌃ ; x.a(y) ! ⌃ ; [y/z]t あたりまえをちゃんと定義するよ
    17. 17. val x = new T ; t Objeceductionルールの読み方 ↓val a:T = tと定 義されている ↓xが... valn a : T = t 2 ⌃(x) ←ルールを適用する前提 (red-value ⌃ ; x.a ! ⌃ ; t ←ルールを適用した結果 ↑各変数の ↑定義する記号 ` binding ´ z : a = t = t 2 ⌃(x)efn axがval S: T : T と定義されているとき、x.aがtに評 (red-method ⌃ ; 価される ! ⌃ ; [y/z]t x.a(y) あたりまえをちゃんと定義するよ
    18. 18. T |M Term traitn A extends = t 2 ⌃(x) Class decl valn a : T ⌃`T x M s, Variable t, u ::= Term(red-value) Field selection ⌃ ; x.a ! ⌃ ; t ⌃ ; val x = new T ; t ! ⌃, x : M ; t x ` ´ Variable (red-new) 評価ルール Method call Object ` defn a z : S : T = t 2 ⌃(x) (red-method) t.a creation ´ Field selection s.a t ⌃ ; x.a(y) ! ⌃ ; [y/z]t Method call ⌃ ; t ! ⌃ 0 ; t0 val x = new T ; t Object creation (red-context) ⌃ ; e[t] ! ⌃ 0 ; e[t0 ] ⌃`T xM Reduction (red-value) ⌃ ; val x = new T ; t ! ⌃, x : M ; t val a : T = t 2 ⌃(x) (red-new)x) n ⌃`T x M (red-method) Lookup (red-value) ⌃ ; x.a !⌃ ; ;t ! ⌃ ; t ⌃ t 0 0 ⌃ ; val x = new T ; t ! ⌃, x : M ; t (red-context) ` ´ ⌃ ; e[t] !i, 0⌃; ` Ti Ni 8 ⌃ e[t0 ] where (red-new) ` 2 defn a z : S : T = t ´ ˘⌃(x) ¯ `U ´ ⌃ ` T | M (red-method) i Ni ] M e ::= (term evaluation context) ⌃ ; x.a(y) ! ⌃ ; [y/z]t (lookup-sig) ⌃ ; thi ⌃ 0 ; t0 ! (red-context) ` ´˘ ¯ ⌃ ; e[t]e.a ⌃ 0 ; e[t0 ] ! traitn A extends T ¯ | M 2 ⌃(y) ` ´˘ e.a (t) ⌃ ` T |M N x.a (s, e, u) Ni where`U ´ ⌃ ` y.A N val x = new E; t i Ni ] M e ::= (term evaluation context) (lookup-class) E ::= (type evaluation context) Lookup (lookup-sig) hi e.A ¯ e.a ` ´˘ ¯ typen A = T 2 ⌃(y) T , E, U | M¯ | M 2 ⌃(y) e.a (t) ` N 8 i, ⌃ ` Ti T M ⌃ Ni where ` ´˘ x.a (s,¯ u) `U e, ´ (lookup-alias) N val ⌃ ` new M ⌃ ` T | M = y.A E;itNi ] M x e ::= (term evaluation context) (lookup-class) E ::= (type evaluation context) (lookup-sig) hi e.A `y) ` ´´ ˘ ¯ ¯ ˘ e.a term evaluation contextわかんない>< |M T , E, U | M 2 ⌃(y) traitn A extends T ` ´˘ ¯ e.a (t) (lookup-alias) ⌃ ` T |M N x.a (s, e, u) ⌃ ` y.A Fig. 5. The FSalg Calculus val x = new E; t N : Syntax & Reduction (lookup-class) E ::= 9 (type evaluation context) e.A
    19. 19. (red-method) ⌃ ; x.a(y) ! ⌃ ; declarations, but we have to check that⌃ 0 ; declaration we are collect its [y/z]t ⌃ ; t ! the t0 0 0 (red-cont not contain the self reference . ⌃ ; e[t] ! ⌃ ; e[t ] ルックアップ規則 The type expansion judgment S, ` T M (third box of Figure 6 larations M of a type T where is used to represent the self reference in M . The expansion of a class type p.A is the expansion of the type signaLookup composed of its parents T and its direct members M (rule -class). T class i, ⌃ ` Ti to Ni set S of locks in order to avoid falling into an in 8 is added the where (for | M ⌃` T ` ´ instance if aU ˘ ¯ ` class extends itself). Rule -type is completely analo ´ i Ni ] M e ::= (term evaluation contex a type alias while performing the same actions on locks in order to prev (lookup-sig) hi expansion. ` ´ ˘ Finally, rule -signature expands a type signature: it sta ¯ e.a traitall extends T and| M 2 merges all collected(t) n A parents T ` ´˘ ¯ then ⌃(y) e.a declarations N with the di of ` type | M N where (s, u) ⌃the T signature. The concatenation withe,rewriting of common m x.a eral sets of declarations is defined by M val x= M |dom(M ) dom(N ) , N , w ⌃ ` y.A N ] N = new E; t (lookup-class) E ::= (type evaluation contex dom(M ) of a sequence of declarations is the set of labels it defines an e.A ` ´˘ ¯ M | n of declarations M to a set of labels L , E, U ofM of those declar typeL A = T 2 ⌃(y) T consists | all define T M L.(lookup-alias) ⌃ ` labels in ⌃ ` y.A M Type and path alias expansion. We introduce here two auxiliary alias expansion and path alias expansion that will be used when definin 型Tが定義しているメソッドを探す judgment. The idea of the type alias expansion judgment S, ` T U we take aFig. 5.TThe FSalg Calculus :alias p.A for another type T 0 , we re type and if T is a type Syntax & Reduction T 0 until we reach a type that is no longer a type alias. This simple behav
    20. 20. Path Typing 型付け規則 x:T 2 S, ` p.type 3 valn a : T (= t)? (path-var) S, `path x : T S, `path p.a : T (path-select)Type Assignment S, `path p : T S, ` s : S (path) S, ` t : T 0 S, ` T 0 <: T S, ` p : p.type ` ´ S, ` S 3 defn a x : T : U (= u)? `´ S, ` s.a t : U (method) S, ` t : S t is not a path S, , x : T ` t : S x 62 fn(S) S, ` S 3 valn a : T (= u)? S, ` T Mc S, ` T wf (select) (new) S, ` t.a : T S, ` val x = new T ; t : SExpansion ` ´˘ ¯S, ` p.type 3 traitn A extends T | M ` ´˘ ¯ S, ` p.type 3 typen A = T {n} [ S, ` T | M N n 62 S {n} [ S, ` T M n 62 S S, 細かいサブルールに分かれているよ ` p.A N ( -class) S, ` p.A M ( -type) 8 i, S, ` Ti Ni ` ´˘ ¯ `U ´ S, ` T |M i Ni ] M
    21. 21. 各記号の意味 The first two boxes of Figure 6 pr judgment S, ` t : T always ass path 式を記録する receives the type p.t p always S: locked declaration。無限ループを防ぐために、使ったssigned a bound T (rule path). A Γ: 型環境 and to項 establish, using the member t: ?declaration valn a : T (= u) ; in th T: 型lect). Note that this rule is only ap Sはちょっと特殊かもback to rule path. Rule method all
    22. 22. パスの型付けPath Typing x:T 2 S, ` p.type 3 valn a : T (= t)? (path-var) S, `path x : T S, `path p.a : T (path-select)Type Assignment S, `path p : T S, ` s : S (path) S, ` t : T 0 S, ` T 0 <: T S, ` p : p.type ` ´ S, ` S 3 defn a x : T : U (= u)? `´ S, ` s.a t : U パスはA.B.T みたいな型のことだよ (method) S, ` t : S t is not a path S, , x : T ` t : S x 62 fn(S) S, ` S 3 valn a : T (= u)? S, ` T Mc S, ` T wf (select) (new)
    23. 23. ( -type) (S, S,` T`wf) N p.A? S, x.A ` `T ´ ˘ | M ¯ wf S, , : ` p.A M ? (wf-x-type) ( -class) ` ´˘ ¯ S, ` type A (= T ) wfx S, ` traitn A extends T | M wfxPath Typing n 8 i, S, ` Ti (wf-x-class) Ni メンバシップ関係 ` ´˘ ¯ `U ´ S, ` T | M i Ni ] M x:T 2 S, ` p.type 3 valn a : wf ( ? -signature) S, ` S, T T (= t) (path-var) S,S, `path xwf `T :T S does not`path p.a singleton types S, contain : T 0 0 ? ` 0 (path-select)? 0 ´ (S, ` t : T S, ` T <: T ) S, , x : S ` t : T S, ` T <: TMembership valn a : T (= t)? wfx ` ´ S, ` S, ` defn a x : S : T (= t)? wfxType Assignment (wf-x-field) (wf-x-method) S, ` p q S, `path q : T T is not a singleton type (p) [ S, S,` T p : 8i, S, (p) 6✓ iS Ni `path M T `T S, `` T wf M s : S 2 fn(Mi ) S, M S, ` / S, 3 [p/]Mi (path) j), S, ` (Ni+jt, :M ) ⌧ Ni3 MiT 0 <: T (3-other) S, S, p.type ` T wf ` ` p : p.type 8 (i, ` ´˘ ¯S, ` S, ` `S, ` (wf-x-signature) T0 T ´ (3-singleton) | M wf 3 defn a x : T : U (= u)? S, ` T S, ` S `´ S, ` s.a t : UPath Alias Expansion (method) S, `6. : The FSalg Calculus : Type Assignment,xExpansion &xMembership Fig. t S t is not a path S, , : T ` t : S 62 fn(S) S, ` `path p : q.type u)? S, S 3 valn a : T (= S, ` T Mc S, `path p :`TT wf S, (p) [ S, ` q q 0 (p) 6✓ S (select) T is not a singleton type (new) S, ` t.a : 0T (-Step) S, ` val x = new T ; t : S (-Refl) S, `pq S, `ppExpansion 10 Fig. 7. The FS alg Calculus´ :˘Well-Formedness and Path Alias Expansion ` ¯S, ` p.type 3 traitn A extends T | M ` ´˘ ¯ S, ` p.type 3 typen A = T {n} [ S, ` T | M N n 62 S {n} [ S, ` T M n 62 S ( -type) S, ` p.A N S, ` p.A M ( -class) 8 i, S, ` Ti Ni ` ´˘ ¯ `U ´ S, ` T |M i Ni ] M ( -signature) 11
    24. 24. Well-FormednessWell-Formedness ` ´˘ ¯ ` ´˘ ¯ S, `path p : T (p) 6✓ S S, , : T | M ` T | M wf (p) [ S, ` T wf ` ´˘ ¯ S, ` T | M wf S, ` p.type wf (wf-signature) (wf-singleton) ` ´˘ ¯ S, ` p.type 3 typen A (= T )?S, ` p.type 3 traitn A extends T | M “ ”? S, ` p.A wf {n} [ S, ` T wf n 62 S (wf-type) (wf-class) S, ` p.A wfMemberWell-Formedness ? ` ´˘ ¯ (S, ` T wf) S, , : x.A ` T | M wf ? (wf-x-type) ` ´˘ ¯ S, ` typen A (= T ) wfx S, ` traitn A extends T | M wfx (wf-x-class) 型Tをnewする前提。目的がわからない>< S, ` S, T wf S, ` T wf S does not contain singleton types ? ` ´? (S, ` t : T0 S, ` T 0 <: T ) S, , x : S ` t : T 0 0 S, ` T <: T ? ` ´ ?
    25. 25. Well-Formdness for Well-Formedness ` ´˘ ¯ ` ´˘ ¯ S, `path p : T (p) 6✓ S S, , : T | M ` T | M wf (p) [ S, ` T wf ` ´˘ ¯ S, ` T | M wf S, ` p.type wf (wf-signature) member (wf-singleton) ` ´˘ ¯ S, ` p.type 3 typen A (= T )? S, ` p.type 3 traitn A extends T | M “ ”? S, ` p.A wf {n} [ S, ` T wf n 62 S (wf-type) (wf-class) S, ` p.A wf MemberWell-Formedness ` ´˘ ¯ (S, ` T wf)? S, , : x.A ` T | M wf (wf-x-type) ` ´˘ ¯ S, ` typen A (= T )? wfx S, ` traitn A extends T | M wfx (wf-x-class) S, ` S, T wf S, ` T wf S does not contain singleton types ? ` ´? (S, ` t : T0 S, ` T 0 <: T ) S, , x : S ` t : T 0 S, ` T 0 <: T ` ´ S, ` valn a : T (= t)? wfx S, ` defn a x : S : T (= t)? wfx (wf-x-field) (wf-x-method) 8i, S, ` Ti Ni S, ` M wf S, ` T wf 8 (i, j), S, ` (Ni+j , M ) ⌧ Ni ` ´˘ ¯ (wf-x-signature) S, ` T | M wf Path Alias Expansion S, `path p : q.type S, `path p : T (p) [ S, ` q q 0 (p) 6✓ S T is not a singleton type (-Step) (-Refl) S, ` p q0 S, `pp こっちも意味がわからない>< Fig. 7. The FSalg Calculus : Well-Formedness and Path Alias Expansion
    26. 26. ` ´˘ ¯ S, ` p.type 3 typen A = T S, ` p.type 3 traitn A extends T | M {n} [ S, ` T U n 62 S S, ` p.A p.A (-type) S, ` p.A U (-class) S, S, サブタイプ ` p.type 3 typen A ` p.A p.A (-abstype) S, S, ` ´˘ ¯ ` ´˘ ` T |M T |M ¯ (-signature) ` p.type p.type (-singleton)Algorithmic Subtyping S, ` T T0 S, ` U U 0 A 6= A0 {n} [ S, ` Ti <: p0 .A0 ´ ˘ n 2 S ` / ¯ S, `⇤ T 0 <: U 0 S, ` p.type 3 traitn A extends T | M S, ` T <: U S, `⇤ p.A <: p0 .A0 (<:-unalias) (<:-class) S, ` p p0 S, ` q p0 S, `⇤ p.type <: q.type S, ` Ti <: p.A (<:-singleton-right) ` ´˘ ¯ (<:-sig-left) S, `⇤ T | M <: p.A U is not a singleton typeS, `pq S, `path q : T S, ` T <: U S, `⇤ p.type <: U T is not a singleton type (<:-singleton-left) 8i, S, ` T <: Ti S, ` T N S, ` p p0 S, ` q p0 dom(M ) ✓ dom(N ) S, ` N ⌧ M ` ´˘ ¯ S, `⇤ p.A <: q.A S, `⇤ T <: T | M (<:-paths) (<:-sig-right)Member SubtypingS, エイリアスのせいでややこしい><S, ` T <: T 0 ` valn a : T (= t)? <: valm a : T 0 (= t0 ) ? S, ` typen A = T <: typen A (= T )? (<:-member-type) (<:-member-field) ` ´˘ ¯ ` ´˘ ¯ S, ` traitn A extends T | M <: traitn A extends T | M (<:-member-class)
    27. 27. S, `⇤ p.type <: q.type S, ` Ti <: p.A (<:-singleton-right) ` ´˘ ¯ (<:-sig-left) S, `⇤ T | M <: p.A U is not a singleton typeS, `pq S, `path q : T S, ` T <: Uメンバ間のサブタイプ関係 S, S, ` p p0 `⇤ p.type <: U S, (<:-singleton-left) ` q p0 T is not a singleton type 8i, S, ` T <: Ti dom(M ) ✓ dom(N ) S, ` T N S, ` N ⌧ M ` ´˘ ¯ S, `⇤ p.A <: q.A S, `⇤ T <: T | M (<:-paths) (<:-sig-right)Member Subtyping S, ` T <: T 0 S, ` typen A = T <: typen A (= T )? ?S, ` valn a : T (= t)? <: valm a : T 0 (= t0 ) (<:-member-type) (<:-member-field) ` ´˘ ¯ ` ´˘ ¯ S, ` traitn A extends T | M <: traitn A extends T | M (<:-member-class) S, ` S 0 <: S S, ` T <: T 0 ` ´ ` ´ (<:-member-method) S, ? ` defn a x : S : T (= t) <: defm a x : S 0 : T 0 (= t0 )? Fig. 8. The FSalg Calculus : Subtyping 12 いっぱいある><
    28. 28. 証明しましょうこの型付け規則が決定的かつ停止することを示す
    29. 29. 決定性の証明命題 この計算は決定的アルゴリズムである 文法と型付け規則が一対一対応するた め、自明 「決定的 = 常に同じ遷移をする」
    30. 30. 型付け規則の停止性命題 型付け規則が停止する• 基本: 規則に関する帰納法で証明する• Sに関する帰納法を使う• 式のサイズ(textual size)が減少することで示す 帰納法で示せないケースは別の尺度で停止性を示 すよ
    31. 31. サブタイプ関係の停止性命題 サブタイプの判定は停止する• 基本: 規則に関する帰納法で証明する• プログラムサイズが有限のため停止する• 背理法を使う 帰納法で示せないケースは別の尺度で停止性を示 すよ
    32. 32. well-formedの停止性命題 well-formedかの判定は停止する• 基本: 規則に関する帰納法で証明する• 背理法を使う 前のやつと同じ
    33. 33. full-Scalaとの違い• Featherweight Scalaの結論をFull Scalaに適用できるか• いくつか違いがあるのでそのままの適用は無理 • 最大の違い: local type inference• 問題にならないようにfull scala compilerには制限が 加えられている よくわかんない><
    34. 34. まとめ
    35. 35. まとめFeatherweight Scalaのtype checkingが決定可能であることを証明しました。

    ×