Created
May 19, 2016 13:32
-
-
Save milessabin/29aaa36a1587c5a8f2fe2ec075715a76 to your computer and use it in GitHub Desktop.
Doing something useful with bare singleton types and no macros ...
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
scala> trait Label[T] { val value: Boolean } | |
defined trait Label | |
scala> def mkInstance(s: String, v: Boolean): Label[s.type] = new Label[s.type] { val value = v } | |
mkInstance: (s: String, v: Boolean)Label[s.type] | |
scala> implicit def lTrue = mkInstance("True", true) | |
lTrue: Label[String("True")] | |
scala> implicit def lFalse = mkInstance("False", false) | |
lFalse: Label[String("False")] | |
scala> def label(s: String)(implicit ls: Label[s.type]): Boolean = ls.value | |
label: (s: String)(implicit ls: Label[s.type])Boolean | |
scala> label("True") | |
res0: Boolean = true | |
scala> label("False") | |
res1: Boolean = false |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment