Skip to content

Instantly share code, notes, and snippets.

@robmwalsh
Last active May 4, 2020 23:46
Show Gist options
  • Save robmwalsh/6b4ccef8aebb13fc146d49d28583c923 to your computer and use it in GitHub Desktop.
Save robmwalsh/6b4ccef8aebb13fc146d49d28583c923 to your computer and use it in GitHub Desktop.
return structural types (or use aux pattern) to hang on to path dependent types
package broken
import broken.Tag._
sealed trait Tag[A]
object Tag {
case object IntTag extends Tag[Int]
case object StringTag extends Tag[String]
}
trait BrokenTestThing {
type A
def feedMyTag(tag: Tag[A]) = ???
}
object BrokenTestThing {
def apply[B](thing: B): BrokenTestThing /*{ //uncomment to fix
type A = B
}*/ =
new BrokenTestThing {
type A = B
}
}
object Test extends App {
val brokenTestThing1 = BrokenTestThing("String")
brokenTestThing1.feedMyTag(StringTag)
val brokenTestThing2 = BrokenTestThing(42)
brokenTestThing2.feedMyTag(IntTag)
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment