Skip to content

Instantly share code, notes, and snippets.

@alexarchambault
Last active August 29, 2015 14:13
Show Gist options
  • Save alexarchambault/ebf6ac15fceccbd37fc5 to your computer and use it in GitHub Desktop.
Save alexarchambault/ebf6ac15fceccbd37fc5 to your computer and use it in GitHub Desktop.
Lazy, labels, and scalaz.@@
[info] Compiling 2 Scala sources to /Users/alexandre/projects/shapeless/examples/target/scala-2.11/classes...
[error] /Users/alexandre/projects/shapeless/examples/src/main/scala/shapeless/examples/TCTag.scala:66: could not find implicit value for parameter e: shapeless.examples.TC[shapeless.examples.TestScalazTag.R]
[error] implicitly[TC[R]] // ...but not for its record
[error] ^
[error] /Users/alexandre/projects/shapeless/examples/src/main/scala/shapeless/examples/TCTag.scala:68: could not find implicit value for parameter e: shapeless.examples.TC[shapeless.examples.DummyTagged]
[error] implicitly[TC[DummyTagged]] // Does *not* work for this one...
[error] ^
[error] /Users/alexandre/projects/shapeless/examples/src/main/scala/shapeless/examples/TCTag.scala:73: could not find implicit value for parameter e: shapeless.examples.TC[shapeless.examples.TestScalazTag.RT]
[error] implicitly[TC[RT]] // ...nor for its record
[error] ^
[error] three errors found
[error] (shapeless-examples/compile:compile) Compilation failed
[error] Total time: 2 s, completed 11 janv. 2015 23:24:07
package shapeless
package examples
import scalaz.@@
import labelled._
import record._
trait TC[T] {
def apply(): String
}
trait CustomTag
object TC {
implicit val intTC: TC[Int] =
new TC[Int] {
def apply() = "Int"
}
implicit val booleanTC: TC[Boolean] =
new TC[Boolean] {
def apply() = "Boolean"
}
implicit val taggedIntTC: TC[Int @@ CustomTag] =
new TC[Int @@ CustomTag] {
def apply() = s"TaggedInt"
}
implicit val hnilTC: TC[HNil] =
new TC[HNil] {
def apply() = "HNil"
}
implicit def hconsTC[H, T <: HList](implicit
headTC: Lazy[TC[H]],
tailTC: Lazy[TC[T]]
): TC[H :: T] =
new TC[H :: T] {
def apply() = s"${headTC.value()} :: ${tailTC.value()}"
}
implicit def projectTC[F, G](implicit
gen: Generic.Aux[F, G],
tc: Lazy[TC[G]]
): TC[F] =
new TC[F] {
def apply() = s"Proj(${tc.value()})"
}
}
case class Dummy(i: Int @@ CustomTag)
case class DummyTagged(b: Boolean, i: Int @@ CustomTag)
object TestScalazTag {
implicitly[TC[Int @@ CustomTag]]
implicitly[TC[Boolean]]
implicitly[TC[Dummy]] // All works here
type L = HList.`Int @@ CustomTag`.T
val gen = Generic[Dummy]
implicitly[gen.Repr =:= L]
implicitly[TC[L]]
implicitly[TC[DummyTagged]]
type LT = HList.`Boolean, Int @@ CustomTag`.T
val gent = Generic[DummyTagged]
implicitly[gent.Repr =:= LT]
implicitly[TC[LT]]
}
package shapeless
package examples
import scalaz.@@
import labelled._
import record._
trait TC[T] {
def apply(): String
}
trait CustomTag
object TC {
implicit val intTC: TC[Int] =
new TC[Int] {
def apply() = "Int"
}
implicit val booleanTC: TC[Boolean] =
new TC[Boolean] {
def apply() = "Boolean"
}
implicit val taggedIntTC: TC[Int @@ CustomTag] =
new TC[Int @@ CustomTag] {
def apply() = s"TaggedInt"
}
implicit val hnilTC: TC[HNil] =
new TC[HNil] {
def apply() = "HNil"
}
implicit def hconsTC[K <: Symbol, H, T <: HList](implicit
key: Witness.Aux[K],
headTC: Lazy[TC[H]],
tailTC: Lazy[TC[T]]
): TC[FieldType[K, H] :: T] =
new TC[FieldType[K, H] :: T] {
def apply() = s"${key.value.name}: ${headTC.value()} :: ${tailTC.value()}"
}
implicit def projectTC[F, G](implicit
lgen: LabelledGeneric.Aux[F, G],
tc: Lazy[TC[G]]
): TC[F] =
new TC[F] {
def apply() = s"Proj(${tc.value()})"
}
}
case class Dummy(i: Int @@ CustomTag)
case class DummyTagged(b: Boolean, i: Int @@ CustomTag)
object TestScalazTag {
implicitly[TC[Int @@ CustomTag]]
implicitly[TC[Boolean]]
implicitly[TC[Dummy]] // Works for this one...
type R = Record.`'i -> Int @@ CustomTag`.T
val lgen = LabelledGeneric[Dummy]
implicitly[lgen.Repr =:= R]
implicitly[TC[R]] // ...but not for its record
implicitly[TC[DummyTagged]] // Does *not* work for this one...
type RT = Record.`'b -> Boolean, 'i -> Int @@ CustomTag`.T
val lgent = LabelledGeneric[DummyTagged]
implicitly[lgent.Repr =:= RT]
implicitly[TC[RT]] // ...nor for its record
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment