How to import inner classes without path dependency in Scala?

TL & DR: Is it possible (locally?) To disable path-specific typing? I would like to issue a single import statement similar to import x._, but to Crefer to X#C, not x.C( X, being a type X)?

I have many types:

class Button[M] { ... }
class Label[M] { ... }
...

And I use them together, passing the same type argument to everyone:

class UseSite[M] (
   btn1 : Button[M]
 , btn2 : Button[M]
 , lbl1 : Label[M]) {
  ...
}

I thought it would be nice to pack all of these types, so I only need to pass the type parameter once:

class Swing[M] {
  class Button { ... }
  class Label { ...}
}

Then on the site used, I would like to do this:

class WithSwing[M] {
  val swing = new Swing[M]
  import swing._
  class UseSite(
     btn1 : Button
   , btn2 : Button
   , lbl1 : Label) {
    ...
  }
}

- : Button swing.Button Swing[M]#Button, UseSite.

Button Swing[M]#Button, swing.Button?

+5
2

, , , - ,

class Button[M]
class Label[M]

trait Swing[M] {
  type ButtonM = Button[M]
  type LabelM = Label[M]
}

class WithSwing[M] {
  val swing = new Swing[M] {}
  import swing._
  class UseSite(btn1 : ButtonM, btn2 : ButtonM, lbl1 : LabelM)
}

WithSwing :

val ws = new WithSwing[String]
import ws.swing._
new ws.UseSite(new ButtonM {}, new ButtonM {}, new LabelM {})

,

class WithSwing[M] extends Swing[M] {
  class UseSite(btn1 : ButtonM, btn2 : ButtonM, lbl1 : LabelM)
}

// Usage ...
val ws = new WithSwing[String]
import ws._
new ws.UseSite(new ButtonM {}, new ButtonM {}, new LabelM {})
+4

-

import Swing[M]#_

Swing[M] , (import , ). , ,

type S = Swing[M]
val b: S#Button = ... // Shorter than Swing[M]#Button
+3

All Articles