Upgrade to Pro — share decks privately, control downloads, hide ads and more …

Scalaの線形化と抽象型メンバーの統一のジレンマ

s10myk4
March 17, 2017

 Scalaの線形化と抽象型メンバーの統一のジレンマ

セプテーニ・オリジナル 下村 朋之(@s10myk47)
@市ヶ谷Geek★Night#12 ScalaMatsuriの余韻トーク〜祭りの余熱〜


s10myk4

March 17, 2017
Tweet

More Decks by s10myk4

Other Decks in Programming

Transcript

  1. ABOUT ME name Լଜ ๎೭(Shimomura Tomoyuki) twitter @s10myk47 organization גࣜձࣾηϓςʔχɾΦϦδφϧ

    team ਓࣄʹ͓͚Δ࠾༻΍഑ଐΛ࠷దԽ͢ΔαʔϏε DDD, Scala, ࠾༻, μʔπ, αοΧʔ
  2. SAMPLE CODE trait A {
 type B <: Any
 val

    b:B
 }
 
 trait ListA {
 self:A =>
 type B <: List[_]
 b.size
 }
  3. SAMPLE CODE trait A {
 type B <: Any
 val

    b:B
 }
 
 trait ListA {
 self:A =>
 type B <: List[_]
 b.size
 } ListAͷ ந৅ܕϝϯόʔB͸ɺListܕΛ্ݶڥքͱ͢ΔͷͰ bͷ αΠζΛऔಘͰ͖Δͱ͜Λظ଴͢Δ
  4. Oops! scala> trait ListA { | self:A => | type

    B <: List[_] | b.size | } <console>:16: error: value size is not a member of ListA.this.B b.size ^
  5. SAMPLE CODE trait A {
 type B <: Any
 val

    b:B
 }
 
 trait ListA {
 self:A =>
 type B <: List[_]
 b.size
 }
  6. Why..? trait A {
 type B <: Any
 val b:B


    }
 
 trait ListA {
 self:A =>
 type B <: List[_]
 b.size
 } trait AͷB͸ AnyΛܧঝ͢Δͱ͍͏੍໿͔࣋ͬͯ͠ͳ͍ Anyʹsizeؔ਺ͳ͍ͷͰ…
  7. Oops! scala> trait ListA { | self:A => | type

    B <: List[_] | b.size | } <console>:16: error: value size is not a member of ListA.this.B b.size ^
  8. What should I do ? trait ListA {
 self:A with

    ListA =>
 type B <: List[_]
 b.size
 } ࣗ෼ܕΞϊςʔγϣϯͰઢܗԽͷॱ൪Λ ListA ͕ޙʹདྷΔΑ ͏ʹ໌ࣔ͢Δ
  9. DOT FIXES THIS! Martin Odersky added a comment - 15/Mar/13

    8:30 AM 
 Paul, you are correct on all counts. This is indeed a fundamental problem in Scala's type system (also in its theory, \nu-Obj): Abstract type members are linearized and the last one wins. It is later checked that that last one has a constraint that implies all others. But there is never a unification of constraints. DOT fixes this.