Skip to content

Instantly share code, notes, and snippets.

@drdozer
Created January 21, 2019 22:42
Show Gist options
  • Save drdozer/ddd27289f72121e812ff3f5589061af2 to your computer and use it in GitHub Desktop.
Save drdozer/ddd27289f72121e812ff3f5589061af2 to your computer and use it in GitHub Desktop.
import scala.language.higherKinds
// log into a trie data structure
trait LogDSL[L] {
def (message: String) log: L
}
object LogDSL {
implicit object LogRecsLogDSL extends LogDSL[String] {
def (message: String) log = message
}
def runLog(ls: String): String = ls
}
trait Direction[D] {
def (erased d: Direction.type) north: D
}
object Direction {
implicit def logDirection[L](implicit L: LogDSL[L]): Direction[L] = new {
override def (erased d: Direction.type) north = "north".log
}
}
object Main {
def main(args: Array[String]): Unit = {
// implicit val ld: Direction[String] = Direction.logDirection[String] // this line makes it work
import Direction.logDirection // this line doesn't help
println("North log")
println(LogDSL.runLog(Direction.logDirection.north(Direction)))
println(LogDSL.runLog(Direction.north))
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment