Last active
December 14, 2015 18:59
-
-
Save mesagie/5132958 to your computer and use it in GitHub Desktop.
Compile-time graph path-finding is possible in Scala
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.implicitConversions | |
// Vertices | |
case class A(l: List[Char]) | |
case class B(l: List[Char]) | |
case class C(l: List[Char]) | |
case class D(l: List[Char]) | |
case class E(l: List[Char]) | |
// Edges | |
implicit def ad[A1 <% A](x: A1) = D(x.l :+ 'A') | |
implicit def bc[B1 <% B](x: B1) = C(x.l :+ 'B') | |
implicit def ce[C1 <% C](x: C1) = E(x.l :+ 'C') | |
implicit def ea[E1 <% E](x: E1) = A(x.l :+ 'E') | |
def pathFrom(end:D) = end | |
pathFrom(B(Nil)) // res0: D = D(List(B, C, E, A)) |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment