Last active
May 4, 2020 23:46
-
-
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
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
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