Skip to content

Instantly share code, notes, and snippets.

@Sciss
Created March 17, 2012 16:01
Show Gist options
  • Save Sciss/2061467 to your computer and use it in GitHub Desktop.
Save Sciss/2061467 to your computer and use it in GitHub Desktop.
OnceMoreImplicits.scala
// this compiles and finds all implicits,
// so no clue why it doesn't work in the real case
trait _Var[ Tx, A ]
trait Sys[ S <: Sys[ S ]] {
type Tx
type Var[ A ] <: _Var[ S#Tx, A ]
def atomic[ A ]( fun: S#Tx => A ) : A
}
trait KSys[ S <: KSys[ S ]] extends Sys[ S ] {
def root[ A ]( init: => A )( implicit tx: S#Tx, ser: Serializer[ S#Tx, A ]) : A
}
trait Serializer[ -Tx, A ]
trait Mutable[ S <: Sys[ S ]]
trait MutableSerializer[ S <: Sys[ S ], A <: Mutable[ S ]] extends Serializer[ S#Tx, A ]
def whatever[ Tx, A ] = new Serializer[ Tx, A ] {}
implicit def option[ Tx, A ]( implicit peer: Serializer[ Tx, A ]) : Serializer[ Tx, Option[ A ]] = whatever
implicit def varSer[ S <: Sys[ S ], A ]( implicit peer: Serializer[ S#Tx, A ]) : Serializer[ S#Tx, S#Var[ A ]] = whatever
trait Test[ S <: KSys[ S ]] {
def s: S
object Node {
implicit object ser extends MutableSerializer[ S, Node ] {
}
}
trait Node extends Mutable[ S ]
s.atomic { implicit tx =>
s.root[ S#Var[ Option[ Node ]]]( sys.error( "TODO" ))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment