Created
January 21, 2019 22:42
-
-
Save drdozer/ddd27289f72121e812ff3f5589061af2 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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