Skip to content

Instantly share code, notes, and snippets.

@doytsujin
Forked from retronym/proxy.scala
Created November 3, 2022 00:21
Show Gist options
  • Save doytsujin/57e173bd0f825da706a37851900af4a1 to your computer and use it in GitHub Desktop.
Save doytsujin/57e173bd0f825da706a37851900af4a1 to your computer and use it in GitHub Desktop.
proxy.scala
package mapmap
trait ECtx
trait KCtx
trait Var[C, T] {
def get(c: C): T
}
trait EVar[T] extends Var[ECtx, T]
trait KVar[T] extends Var[KCtx, T] {
def range(c: KCtx, vStart: Int, vStop: Int): Traversable[T]
}
trait Proc[C <: Proxy] {
val proxy: C
def switch: proxy.v[Boolean]
}
trait Proxy {
type Ctx
type v[X] <: Var[Ctx, X]
}
trait EProxy extends Proxy {
def ectx: ECtx
type Ctx = ECtx
}
object test {
def eTest[C <: EProxy](p: Proc[C], c: C) {
p.switch.get(c.ectx)
}
/// above compile ok until here
trait KProxy extends Proxy {
def kctx: KCtx
type Ctx = KCtx
type v[X] <: KVar[X]
// ouch! this doesn't compile
}
def kTest[C <: KProxy](p: Proc[C], c: C) {
p.switch.get(c.kctx)
p.switch.range(c.kctx, 1, 2)
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment