Created
February 22, 2017 16:17
-
-
Save odersky/040b88501bac8cfd6cbbd856b0836ae3 to your computer and use it in GitHub Desktop.
Phantom 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
object Phantom { | |
type Nothing <: Any | |
type Any | |
def assume[T <: Any]: T | |
class Function1[-T <: Any, +R <: Any] { | |
def apply(x: T): R | |
} | |
class ImplicitFunction1[-T <: Any, +R <: Any] extends Function1[T, R] { | |
def apply(implicit x: T): R | |
} | |
... same for other arities ... | |
} | |
object X { | |
type CanScare[Int] <: Phantom.Any | |
def canScare: CanScare[Int] = Phantom.assume[CanScare[Int]] | |
} | |
Rules: | |
No mixing of phantom and non-phantom |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment