Skip to content

Instantly share code, notes, and snippets.

@jorgeortiz85
Created September 21, 2011 16:29
Show Gist options
  • Save jorgeortiz85/1232550 to your computer and use it in GitHub Desktop.
Save jorgeortiz85/1232550 to your computer and use it in GitHub Desktop.
attempt at newtype in Scala for FKs
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)
}
}
@jorgeortiz85
Copy link
Author

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