SlideShare ist ein Scribd-Unternehmen logo
1 von 35
Featherweight Scalaの紹介および
型付け規則の決定性について

          @mzp
元論文
“A Core Calculus for Scala Type Checking”
 - Vincent Cremet, François Garillot, Sergueï
Lenglet, Martin Odersky
Proceedings of MFCS 06, Stará Lesná, August 2006.




       細かい証明はこっちを読んでね
今日やること
1. Featherweight Sacalの文法・評価ルールの
 定義

2. 型付け規則の定義

3. 型付け規則の決定可能性を証明


      決定可能性 := 決定的アルゴリズム + 停止性
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 type
there is a general encoding that lets one encode all forms of parameterized type
into 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に影響されてるよ
}

          Scalaとの違い
The List example showed how genericity can be e
there is a general encoding that lets one encode all
into 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(
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(): Boolean
trait 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
syntactic sugar so this is done automatically whenever a first-class function valu
in 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 the
these 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 Featherwei
makes use of a wrapper class Mapper which defines two abstract types A and
trait 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
     The
and 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
        result
and 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-cla
However, val tl = this0.map(f, xs.tail()) be generalized to polymorphic functions. T
        };
             the construction cannot
is that result
         polymorphic functions like map have to be encoded using wrapper clas
wrapper classes are first-class values neither in Featherweight nor in regular
     }
}
Featherweight Scalaの
       定義
文法定義
Syntax
x, y, z, '                     Variable
a                              Value label           p ::=                Path
A                              Type label                 x                 Variable
                                                          p.a               Field selection
P ::=˘      ¯                  Program
      x|M t                                          S, T, U ::=  Type
                                                          p.A       Type selection
                                                          p.type
                                                          ` ´˘   ¯ Singleton type
M, 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 decl
s, t, u ::=                    Term
      x                          Variable
      t.a ` ´                    Field selection
      s.a t                      Method call
      val x = new T ; t          Object creation

Reduction

   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 ]
val x = new T ; t              Objec

eductionルールの読み方

  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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方

  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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方

  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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方

  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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方

  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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方
                  ↓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

         あたりまえをちゃんと定義するよ
val x = new T ; t              Objec

eductionルールの読み方
   ↓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

         あたりまえをちゃんと定義するよ
val x = new T ; t               Objec

eductionルールの読み方
   ↓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)

          あたりまえをちゃんと定義するよ
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
(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 signa
Lookup
        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
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 : S


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
             S,    細かいサブルールに分かれているよ
                   ` p.A N     '
                           ( -class)
                                     S, ` p.A M                        '
                                                                                      ( -type)


                                                         8 i, S, ` Ti ' Ni
                                                        ` ´˘      ¯    `U     ´
                                                 S,    ` T '|M       '    i Ni ] M
各記号の意味
 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
パスの型付け

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)
( -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 wfx
Path 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 <: T
Membership valn a : T (= t)? wfx                                    `    ´
       S, `                                          S, ` defn a x : S : T (= t)? wfx
Type 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 : U
Path 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,     `p'q                                                S,   `p'p

Expansion                                         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
Well-Formedness
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)
                                    (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)
                              型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
                                        ?                                    `    ´       ?
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,   `p'p


      こっちも意味がわからない><
         Fig. 7. The FSalg Calculus : Well-Formedness and Path Alias Expansion
` ´˘     ¯
      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 type
S,    `p'q     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 Subtyping



S,
          エイリアスのせいでややこしい><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)
S,    `⇤ p.type <: q.type                          S, ` Ti <: p.A
                         (<:-singleton-right)                   ` ´˘      ¯     (<:-sig-left)
                                                         S,   `⇤ T ' | M <: p.A
           U is not a singleton type
S,    `p'q     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
                  いっぱいある><
証明しましょう
この型付け規則が決定的かつ停止するこ
とを示す
決定性の証明
命題

 この計算は決定的アルゴリズムである

 文法と型付け規則が一対一対応するた
 め、自明



     「決定的 = 常に同じ遷移をする」
型付け規則の停止性
命題

          型付け規則が停止する

•   基本: 規則に関する帰納法で証明する

•   Sに関する帰納法を使う

•   式のサイズ(textual size)が減少することで示す

        帰納法で示せないケースは別の尺度で停止性を示
        すよ
サブタイプ関係の停止性
命題

     サブタイプの判定は停止する

• 基本: 規則に関する帰納法で証明する
• プログラムサイズが有限のため停止する
• 背理法を使う
     帰納法で示せないケースは別の尺度で停止性を示
     すよ
well-formedの停止性
命題

     well-formedかの判定は停止する

• 基本: 規則に関する帰納法で証明する
• 背理法を使う


     前のやつと同じ
full-Scalaとの違い
•   Featherweight Scalaの結論をFull Scalaに適用できるか

•   いくつか違いがあるのでそのままの適用は無理

    •   最大の違い: local type inference

•   問題にならないようにfull scala compilerには制限が
    加えられている



           よくわかんない><
まとめ
まとめ
Featherweight Scalaのtype checkingが決定
可能であることを証明しました。

Weitere ähnliche Inhalte

Was ist angesagt?

Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsRai University
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesTomer Gabel
 
Type Parameterization
Type ParameterizationType Parameterization
Type ParameterizationKnoldus Inc.
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and stringsRai University
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsRai University
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statementsRai University
 
Monads and friends demystified
Monads and friends demystifiedMonads and friends demystified
Monads and friends demystifiedAlessandro Lacava
 
TI1220 Lecture 8: Traits & Type Parameterization
TI1220 Lecture 8: Traits & Type ParameterizationTI1220 Lecture 8: Traits & Type Parameterization
TI1220 Lecture 8: Traits & Type ParameterizationEelco Visser
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from javaIndicThreads
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceAlexey Raga
 
Chapter 13.1.7
Chapter 13.1.7Chapter 13.1.7
Chapter 13.1.7patcha535
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsKirill Kozlov
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)stasimus
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2Hang Zhao
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2Hang Zhao
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type ClassesJohn De Goes
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキストOpt Technologies
 

Was ist angesagt? (20)

Btech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and stringsBtech i pic u-4 function, storage class and array and strings
Btech i pic u-4 function, storage class and array and strings
 
Scala Back to Basics: Type Classes
Scala Back to Basics: Type ClassesScala Back to Basics: Type Classes
Scala Back to Basics: Type Classes
 
Type Parameterization
Type ParameterizationType Parameterization
Type Parameterization
 
Diploma ii cfpc u-4 function, storage class and array and strings
Diploma ii  cfpc u-4 function, storage class and array and stringsDiploma ii  cfpc u-4 function, storage class and array and strings
Diploma ii cfpc u-4 function, storage class and array and strings
 
Bsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and stringsBsc cs i pic u-4 function, storage class and array and strings
Bsc cs i pic u-4 function, storage class and array and strings
 
handling input output and control statements
 handling input output and control statements handling input output and control statements
handling input output and control statements
 
Monads and friends demystified
Monads and friends demystifiedMonads and friends demystified
Monads and friends demystified
 
TI1220 Lecture 8: Traits & Type Parameterization
TI1220 Lecture 8: Traits & Type ParameterizationTI1220 Lecture 8: Traits & Type Parameterization
TI1220 Lecture 8: Traits & Type Parameterization
 
Scala for curious
Scala for curiousScala for curious
Scala for curious
 
Scala collections api expressivity and brevity upgrade from java
Scala collections api  expressivity and brevity upgrade from javaScala collections api  expressivity and brevity upgrade from java
Scala collections api expressivity and brevity upgrade from java
 
Type classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritanceType classes 101 - classification beyond inheritance
Type classes 101 - classification beyond inheritance
 
Chapter 13.1.7
Chapter 13.1.7Chapter 13.1.7
Chapter 13.1.7
 
Scala. Introduction to FP. Monads
Scala. Introduction to FP. MonadsScala. Introduction to FP. Monads
Scala. Introduction to FP. Monads
 
Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)Introduction to Monads in Scala (2)
Introduction to Monads in Scala (2)
 
Fp in scala part 2
Fp in scala part 2Fp in scala part 2
Fp in scala part 2
 
Fp in scala with adts part 2
Fp in scala with adts part 2Fp in scala with adts part 2
Fp in scala with adts part 2
 
Refactoring Functional Type Classes
Refactoring Functional Type ClassesRefactoring Functional Type Classes
Refactoring Functional Type Classes
 
08. haskell Functions
08. haskell Functions08. haskell Functions
08. haskell Functions
 
Frp2016 3
Frp2016 3Frp2016 3
Frp2016 3
 
学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト学生向けScalaハンズオンテキスト
学生向けScalaハンズオンテキスト
 

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

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... FunctionsMichal Bigos
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scalaRaymond Tay
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...PROIDEA
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Philip Schwarz
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scaladjspiewak
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meetMario Fusco
 
学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2Opt Technologies
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with ScalaDenis
 
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQProvectus
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming LanguageMikhail Barash
 
Scala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectiveScala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectivegabalese
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaVladimir Kostyukov
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming iiPrashant Kalkar
 

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

All About ... Functions
All About ... FunctionsAll About ... Functions
All About ... Functions
 
Functional programming with_scala
Functional programming with_scalaFunctional programming with_scala
Functional programming with_scala
 
Scala for Jedi
Scala for JediScala for Jedi
Scala for Jedi
 
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
JDD2015: Functional programing and Event Sourcing - a pair made in heaven - e...
 
Sequence and Traverse - Part 3
Sequence and Traverse - Part 3Sequence and Traverse - Part 3
Sequence and Traverse - Part 3
 
High Wizardry in the Land of Scala
High Wizardry in the Land of ScalaHigh Wizardry in the Land of Scala
High Wizardry in the Land of Scala
 
Zippers
ZippersZippers
Zippers
 
Scala - where objects and functions meet
Scala - where objects and functions meetScala - where objects and functions meet
Scala - where objects and functions meet
 
学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2学生向けScalaハンズオンテキスト part2
学生向けScalaハンズオンテキスト part2
 
Scala
ScalaScala
Scala
 
Demystifying functional programming with Scala
Demystifying functional programming with ScalaDemystifying functional programming with Scala
Demystifying functional programming with Scala
 
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
[Expert Fridays] Александр Чичигин - Как перестать бояться и полюбить COQ
 
Introducing scala
Introducing scalaIntroducing scala
Introducing scala
 
Bound
BoundBound
Bound
 
Scala Bootcamp 1
Scala Bootcamp 1Scala Bootcamp 1
Scala Bootcamp 1
 
Xtend Programming Language
Xtend Programming LanguageXtend Programming Language
Xtend Programming Language
 
Scala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspectiveScala or functional programming from a python developer's perspective
Scala or functional programming from a python developer's perspective
 
Ch5a
Ch5aCh5a
Ch5a
 
Purely Functional Data Structures in Scala
Purely Functional Data Structures in ScalaPurely Functional Data Structures in Scala
Purely Functional Data Structures in Scala
 
Functional programming ii
Functional programming iiFunctional programming ii
Functional programming ii
 

Mehr von Hiroki Mizuno

TypeSafe OSの試み
TypeSafe OSの試みTypeSafe OSの試み
TypeSafe OSの試みHiroki Mizuno
 
OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法Hiroki Mizuno
 
#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書についてHiroki Mizuno
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Hiroki Mizuno
 
Darcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcDarcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcHiroki Mizuno
 
Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Hiroki Mizuno
 
CoqによるMsgPackの証明
CoqによるMsgPackの証明CoqによるMsgPackの証明
CoqによるMsgPackの証明Hiroki Mizuno
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)Hiroki Mizuno
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会Hiroki Mizuno
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Hiroki Mizuno
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議Hiroki Mizuno
 
Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発Hiroki Mizuno
 
NGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへNGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへHiroki Mizuno
 
From Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへFrom Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへHiroki Mizuno
 
OCamlAPISearchの紹介
OCamlAPISearchの紹介OCamlAPISearchの紹介
OCamlAPISearchの紹介Hiroki Mizuno
 

Mehr von Hiroki Mizuno (20)

TypeSafe OSの試み
TypeSafe OSの試みTypeSafe OSの試み
TypeSafe OSの試み
 
OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法OCamlでWebアプリケーションを作るn個の方法
OCamlでWebアプリケーションを作るn個の方法
 
#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について#NGK2012B Excelによる設計書について
#NGK2012B Excelによる設計書について
 
Java基礎
Java基礎Java基礎
Java基礎
 
Sml#探検隊
Sml#探検隊Sml#探検隊
Sml#探検隊
 
どこでもCoq
どこでもCoqどこでもCoq
どこでもCoq
 
Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋Coq for Moblie Phone @ ML名古屋
Coq for Moblie Phone @ ML名古屋
 
Darcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbcDarcs紹介@20120423-scmbc
Darcs紹介@20120423-scmbc
 
Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力Gallinaによる証明駆動開発の魅力
Gallinaによる証明駆動開発の魅力
 
CoqによるMsgPackの証明
CoqによるMsgPackの証明CoqによるMsgPackの証明
CoqによるMsgPackの証明
 
「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)「Frama-Cによるソースコード検証」 (mzp)
「Frama-Cによるソースコード検証」 (mzp)
 
20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会20110424 action scriptを使わないflash勉強会
20110424 action scriptを使わないflash勉強会
 
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02Coq to Rubyによる証明駆動開発@名古屋ruby会議02
Coq to Rubyによる証明駆動開発@名古屋ruby会議02
 
証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議証明駆動開発のたのしみ@名古屋reject会議
証明駆動開発のたのしみ@名古屋reject会議
 
Coqによる証明駆動開発
Coqによる証明駆動開発Coqによる証明駆動開発
Coqによる証明駆動開発
 
NGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへNGK忘年会 2010 / CoqからRubyへ
NGK忘年会 2010 / CoqからRubyへ
 
From Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへFrom Coq to Ruby / CoqからRubyへ
From Coq to Ruby / CoqからRubyへ
 
SacalaZa #1
SacalaZa #1SacalaZa #1
SacalaZa #1
 
CoqUn2010
CoqUn2010CoqUn2010
CoqUn2010
 
OCamlAPISearchの紹介
OCamlAPISearchの紹介OCamlAPISearchの紹介
OCamlAPISearchの紹介
 

Kürzlich hochgeladen

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEarley Information Science
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century educationjfdjdjcjdnsjd
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...Neo4j
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Enterprise Knowledge
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationMichael W. Hawkins
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerThousandEyes
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsEnterprise Knowledge
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Igalia
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking MenDelhi Call girls
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)Gabriella Davis
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdfhans926745
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationSafe Software
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking MenDelhi Call girls
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 

Kürzlich hochgeladen (20)

EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptxEIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
EIS-Webinar-Prompt-Knowledge-Eng-2024-04-08.pptx
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...Workshop - Best of Both Worlds_ Combine  KG and Vector search for  enhanced R...
Workshop - Best of Both Worlds_ Combine KG and Vector search for enhanced R...
 
Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...Driving Behavioral Change for Information Management through Data-Driven Gree...
Driving Behavioral Change for Information Management through Data-Driven Gree...
 
GenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day PresentationGenCyber Cyber Security Day Presentation
GenCyber Cyber Security Day Presentation
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
IAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI SolutionsIAC 2024 - IA Fast Track to Search Focused AI Solutions
IAC 2024 - IA Fast Track to Search Focused AI Solutions
 
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
Raspberry Pi 5: Challenges and Solutions in Bringing up an OpenGL/Vulkan Driv...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men08448380779 Call Girls In Greater Kailash - I Women Seeking Men
08448380779 Call Girls In Greater Kailash - I Women Seeking Men
 
A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)A Domino Admins Adventures (Engage 2024)
A Domino Admins Adventures (Engage 2024)
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf[2024]Digital Global Overview Report 2024 Meltwater.pdf
[2024]Digital Global Overview Report 2024 Meltwater.pdf
 
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time AutomationFrom Event to Action: Accelerate Your Decision Making with Real-Time Automation
From Event to Action: Accelerate Your Decision Making with Real-Time Automation
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men08448380779 Call Girls In Friends Colony Women Seeking Men
08448380779 Call Girls In Friends Colony Women Seeking Men
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 

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

  • 2. 元論文 “A Core Calculus for Scala Type Checking” - Vincent Cremet, François Garillot, Sergueï Lenglet, Martin Odersky Proceedings of MFCS 06, Stará Lesná, August 2006. 細かい証明はこっちを読んでね
  • 3. 今日やること 1. Featherweight Sacalの文法・評価ルールの 定義 2. 型付け規則の定義 3. 型付け規則の決定可能性を証明 決定可能性 := 決定的アルゴリズム + 停止性
  • 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 type there is a general encoding that lets one encode all forms of parameterized type into 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. } Scalaとの違い The List example showed how genericity can be e there is a general encoding that lets one encode all into 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. 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(): Boolean trait 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. syntactic sugar so this is done automatically whenever a first-class function valu in 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 the these 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 Featherwei makes use of a wrapper class Mapper which defines two abstract types A and trait 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 The and 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 result and 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-cla However, val tl = this0.map(f, xs.tail()) be generalized to polymorphic functions. T }; the construction cannot is that result polymorphic functions like map have to be encoded using wrapper clas wrapper classes are first-class values neither in Featherweight nor in regular } }
  • 9. 文法定義 Syntax x, y, z, ' Variable a Value label p ::= Path A Type label x Variable p.a Field selection P ::=˘ ¯ Program x|M t S, T, U ::= Type p.A Type selection p.type ` ´˘ ¯ Singleton type M, 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 decl s, t, u ::= Term x Variable t.a ` ´ Field selection s.a t Method call val x = new T ; t Object creation Reduction 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. val x = new T ; t Objec eductionルールの読み方 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. val x = new T ; t Objec eductionルールの読み方 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. val x = new T ; t Objec eductionルールの読み方 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. val x = new T ; t Objec eductionルールの読み方 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. val x = new T ; t Objec eductionルールの読み方 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. val x = new T ; t Objec eductionルールの読み方 ↓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. val x = new T ; t Objec eductionルールの読み方 ↓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. val x = new T ; t Objec eductionルールの読み方 ↓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. 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. (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 signa Lookup 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. 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 : S 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 S, 細かいサブルールに分かれているよ ` p.A N ' ( -class) S, ` p.A M ' ( -type) 8 i, S, ` Ti ' Ni ` ´˘ ¯ `U ´ S, ` T '|M ' i Ni ] M
  • 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. パスの型付け 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. ( -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 wfx Path 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 <: T Membership valn a : T (= t)? wfx ` ´ S, ` S, ` defn a x : S : T (= t)? wfx Type 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 : U Path 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, `p'q S, `p'p Expansion 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. Well-Formedness 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) (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) 型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. 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, `p'p こっちも意味がわからない>< Fig. 7. The FSalg Calculus : Well-Formedness and Path Alias Expansion
  • 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 type S, `p'q 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 Subtyping S, エイリアスのせいでややこしい><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. S, `⇤ p.type <: q.type S, ` Ti <: p.A (<:-singleton-right) ` ´˘ ¯ (<:-sig-left) S, `⇤ T ' | M <: p.A U is not a singleton type S, `p'q 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 いっぱいある><
  • 30. 型付け規則の停止性 命題 型付け規則が停止する • 基本: 規則に関する帰納法で証明する • Sに関する帰納法を使う • 式のサイズ(textual size)が減少することで示す 帰納法で示せないケースは別の尺度で停止性を示 すよ
  • 31. サブタイプ関係の停止性 命題 サブタイプの判定は停止する • 基本: 規則に関する帰納法で証明する • プログラムサイズが有限のため停止する • 背理法を使う 帰納法で示せないケースは別の尺度で停止性を示 すよ
  • 32. well-formedの停止性 命題 well-formedかの判定は停止する • 基本: 規則に関する帰納法で証明する • 背理法を使う 前のやつと同じ
  • 33. full-Scalaとの違い • Featherweight Scalaの結論をFull Scalaに適用できるか • いくつか違いがあるのでそのままの適用は無理 • 最大の違い: local type inference • 問題にならないようにfull scala compilerには制限が 加えられている よくわかんない><

Hinweis der Redaktion

  1. \n
  2. &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
  3. \n
  4. \n
  5. 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
  6. \n
  7. \n
  8. \n
  9. \n
  10. \n
  11. \n
  12. \n
  13. \n
  14. \n
  15. \n
  16. \n
  17. \n
  18. 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
  19. &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
  20. \n
  21. \n
  22. \n
  23. 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
  24. &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
  25. \n
  26. \n
  27. \n
  28. \n
  29. \n
  30. \n
  31. \n
  32. \n
  33. \n
  34. \n
  35. \n