-
Notifications
You must be signed in to change notification settings - Fork 531
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Interaction between Lazy and tagged types #584
Comments
The problem appears to be that the tags prevent the |
I was playing with this trying to understand what is the issue and I managed to reduce the example to something smaller. I also noticed a pattern depending how you define the implicit import shapeless._, tag._
object Main {
sealed trait Readable[A]
sealed trait IdTag
type Id = String @@ IdTag
// Method 1
//implicit def taggedStringReadable[T]: Readable[String @@ T] = new Readable[String @@ T] { }
// Method 2
//implicit def taggedStringReadable[T, M[_, _]](
// implicit ev: @@[String, T] =:= M[String, T]): Readable[M[String, T]] = new Readable[M[String, T]] { }
implicitly[Readable[Id]] // always compiles
implicitly[Strict[Readable[Id]]] // doesn't compile with 2
implicitly[Lazy[Readable[Id]]] // doesn't compile with 2
} Method 1 works with |
My bet is on calls to def foo[M[_, _], A, B](mab: M[A, B]) = mab
def bar(book: Book) = {
foo(book.id: BookId) // ok
foo(book.id: String @@ BookTag) // ok
foo(book.id: String with Tagged[BookTag])
// [error] found : String with shapeless.tag.Tagged[LazyTagged.BookTag]
// [error] required: scala.collection.IndexedSeqOptimized[A,B]
// [error] foo(book.id: String with Tagged[BookTag])
} since Scala can't unify the refinement type |
There is an interaction between
Lazy
and tagged types with respect to the automatic derivation of typeclasses; to reproduce it this is a simple example:In this case the derivation fails for both
Customer
andBook
. Interestingly enough removing theLazy
inhconsReadable
it compiles; in this case I could just remove it but when the derivation is used in third party libraries that won't compile without Lazy this could be a problem.The text was updated successfully, but these errors were encountered: