-
-
Save snoble/0385b32e8699843e0b2034b749f66734 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
sealed trait TList[X, Z] | |
case class TCons[X, Y, Z](head: X => Y, tail: TList[Y,Z]) extends TList[X, Z] | |
case class TEnd[X,Z](f: X => Z) extends TList[X, Z] | |
object Evaluators { | |
def safe1[X,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case TCons(head, tail) => safe1(head(x), tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Warning | |
// scala: Fine | |
def unsafe1[X,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case TCons(head, tail) => safe1("WTF", tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Warning | |
// scala: Fine | |
def safe2[X,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case tCons: TCons[X, _, Z] => safe2(tCons.head(x), tCons.tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Error | |
// scala: Fine | |
def unsafe2[X,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case tCons: TCons[X, _, Z] => unsafe2("WTF", tCons.tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Error | |
// scala: Error | |
def safe3[X,Y,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case tCons: TCons[X, Y, Z] => safe3(tCons.head(x), tCons.tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Fine | |
// scala: Warning (Erasure) | |
def unsafe3[X,Y,Z](x: X, tList: TList[X, Z]): Z = tList match { | |
case tCons: TCons[X, Y, Z] => unsafe3("WTF", tCons.tail) | |
case TEnd(f) => f(x) | |
} | |
// dotty: Error | |
// scala: Error | |
} |
aaronlevin
commented
Jan 11, 2018
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment