Skip to content

Instantly share code, notes, and snippets.

@AlecZorab
Last active April 27, 2016 13:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AlecZorab/7aa949ab898932f6891264189028335f to your computer and use it in GitHub Desktop.
Save AlecZorab/7aa949ab898932f6891264189028335f to your computer and use it in GitHub Desktop.
Record Voodoo
Welcome to Scala version 2.11.7 (Java HotSpot(TM) 64-Bit Server VM, Java 1.8.0_66).
Type in expressions to have them evaluated.
Type :help for more information.
scala> import shapeless._ ; import syntax.singleton._ ; import record._
import shapeless._
import syntax.singleton._
import record._
scala> import prelude._
import prelude._
scala> val p: ((() => String) with shapeless.labelled.KeyTag[Witness.`"misery"`.T,() => String]) :: ((() => String) with shapeless.labelled.KeyTag[Witness.`"print"`.T,() => String]) :: HNil = {
| ("misery" ->> (() => "Woe!")) :: ("print" ->> (() => s"${p("misery") $ (_())}")) :: HNil
| }
p: shapeless.::[() => String with shapeless.labelled.KeyTag[String("misery"),() => String],shapeless.::[() => String with shapeless.labelled.KeyTag[String("print"),() => String],shapeless.HNil]] = <function0> :: <function0> :: HNil
scala> val o: ((() => String) with shapeless.labelled.KeyTag[Witness.`"happy"`.T,() => String]) :: ((() => String) with shapeless.labelled.KeyTag[Witness.`"print"`.T,() => String]) :: HNil = {
| ("happy" ->> (() => "Joy!")) :: ("print" ->> (() => s"${o("happy") $ (_())}")) :: HNil
| }
o: shapeless.::[() => String with shapeless.labelled.KeyTag[String("happy"),() => String],shapeless.::[() => String with shapeless.labelled.KeyTag[String("print"),() => String],shapeless.HNil]] = <function0> :: <function0> :: HNil
scala> o("print") $ (_())
res0: String = Joy!
scala> p("print") $ (_())
res1: String = Woe!
scala> List(o, p)
res2: List[shapeless.::[() => String with shapeless.labelled.KeyTag[_ >: String("misery") with String("happy") <: String, () => String],shapeless.::[() => String with shapeless.labelled.KeyTag[String("print"),() => String],shapeless.HNil]]] = List(<function0> :: <function0> :: HNil, <function0> :: <function0> :: HNil)
scala> List(o, p) map (r => r("print") $ (_()))
<console>:25: error: No field String("print") in record shapeless.::[() => String with shapeless.labelled.KeyTag[_ >: String("misery") with String("happy") <: String, () => String],shapeless.::[() => String with shapeless.labelled.KeyTag[String("print"),() => String],shapeless.HNil]]
List(o, p) map (r => r("print") $ (_()))
^
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment