Created
September 21, 2011 16:29
-
-
Save jorgeortiz85/1232550 to your computer and use it in GitHub Desktop.
attempt at newtype in Scala for FKs
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
class FK[A] extends StaticAnnotation | |
class User | |
class Checkin | |
object Main { | |
def fetch[A](id: Int @ FK[A]): A = null.asInstanceOf[A] | |
def main(args: Array[String]): Unit = { | |
val id: Int @ FK[Checkin] = 10 | |
// Why does this type check? | |
fetch[User](id) | |
} | |
} |
Pretty hot, thanks! Miles' approach looks promising, but if it doesn't work out I'll give this a shot.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Miles' approach might have obviated the need for annotation checking, but I think you can add extra typechecking with a custom AnnotationChecker.
AnnotationCheckers:
Typers:662
Types:4458