I would like to move a type parameter to a type member.
This is the starting point which works:
trait Sys[S <: Sys[S]] {
type Tx
type Id <: Identifier[S#Tx]
}
trait Identifier[Tx] {
def dispose()(implicit tx: Tx): Unit
}
trait Test[S <: Sys[S]] {
def id: S#Id
def dispose()(implicit tx: S#Tx) {
id.dispose()
}
}
What annoys me is that I'm carrying around a type parameter [S <: Sys[S]]
throughout my entire libraries. So what I was thinking is this:
trait Sys {
type S = this.type // ?
type Tx
type Id <: Identifier[S#Tx]
}
trait Identifier[Tx] {
def dispose()(implicit tx: Tx): Unit
}
trait Test[S <: Sys] {
def id: S#Id
def dispose()(implicit tx: S#Tx) {
id.dispose()
}
}
Which fails... S#Tx
and S#Id
became somehow detached:
error: could not find implicit value for parameter tx: _9.Tx
id.dispose()
^
Any tricks or changes that make it work?
EDIT : To clarify, I am primarily hoping to fix the type S
in Sys
to make it work. There are numerous problems in my case using path-dependent types. To give just one example which reflects the answers of pedrofuria and Owen:
trait Foo[S <: Sys] {
val s: S
def id: s.Id
def dispose()(implicit tx: s.Tx) {
id.dispose()
}
}
trait Bar[S <: Sys] {
val s: S
def id: s.Id
def foo: Foo[S]
def dispose()(implicit tx: s.Tx) {
foo.dispose()
id.dispose()
}
}
<console>:27: error: could not find implicit value for parameter tx: _106.s.Tx
foo.dispose()
^
Try to make that def foo: Foo[s.type]
to give you an idea that this leads nowhere.
object someSys extends Sys[someSys] { ... }
? – Huldahuldahobject DurableSys extends Sys[DurableSys]
etc. This does work. So the question is, can I get rid of the type parameter onSys
which really pollutes my sources. – Mannos