Skip to content
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

Deriving TagKK[F[Either]] with TagK[F] in context (scala 2.13 only) #515

Open
road21 opened this issue Jan 30, 2025 · 2 comments
Open

Deriving TagKK[F[Either]] with TagK[F] in context (scala 2.13 only) #515

road21 opened this issue Jan 30, 2025 · 2 comments

Comments

@road21
Copy link

road21 commented Jan 30, 2025

This code is not compiling in scala 2.13.16:

import izumi.reflect.{TagK, TagKK, HKTag}

type Mono[F[_], x, y] = F[Either[x, y]]

def foo[F[_]: TagK]: TagKK[Mono[F, *, *]]] =
  implicitly // compiler error: could not find implicit value for parameter e: izumi.reflect.TagKK[[β$0$, γ$1$]F[scala.util.Either[β$0$,γ$1$]]]

The same code is compiling in scala 3 without compiler errors:

//> using scala 3.6.2
//> using dep "dev.zio::izumi-reflect:3.0.0"
import izumi.reflect.{TagK, TagKK, HKTag}

type Mono[F[_], x, y] = F[Either[x, y]]

def foo[F[_]: TagK]: TagKK[[x, y] =>> Mono[F, x, y]] = 
  implicitly // ok

As a workaround type Mono[F[_], x, y] >: F[Either[x, y]] <: F[Either[x, y]] works.

Scastie: https://scastie.scala-lang.org/road21/j3t7ODHHQzqjYW0hPysctg/30

@neko-kai
Copy link
Member

neko-kai commented Jan 30, 2025

@road21 Interesting, this looks like a type inference issue on Scala 2, not a bug in the macro itself. If the TagKK type is inlined to its underlying HKTag form, it works:

import izumi.reflect.{TagK, TagKK}

type Mono[F[_], x, y] = F[Either[x, y]]

def test[F[_]: TagK]: TagKK[Mono[F, *, *]] = implicitly[HKTag[{ type Arg[A, B] = Mono[F, A, B] }]]

println(test[Option].tag.debug())
// ⚙️ begin : λ %1,%2 → scala.Option[+scala.util.Either[+1,+2]]

Additionally, the trace on explicit macro invocation is weird:

def test[F[_]: TagK]: TagKK[Mono[F, *, *]] = izumi.reflect.HKTag.hktagFromTagMacro
could not find implicit value for izumi.reflect.Tag[A]. Did you forget to put on a Tag, TagK or TagKK context bound on one of the parameters in A? e.g. def x[T: Tag, F[_]: TagK] = ...


<trace>: 
  deriving Tag for A, dealiased: A:
  could not find implicit value for Tag[A]: A is a type parameter without an implicit Tag!
      def test[F[_]: TagK]: TagKK[Mono[F, *, *]] = izumi.reflect.HKTag.hktagFromTagMacro

What is A here? It seems to be an artefact of type inference.

It would be great to minimize this so as not to require the macro and report to Scala 2 upstream...

@road21
Copy link
Author

road21 commented Jan 31, 2025

Thank you very much for the quick response!
I will try to minimize it

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants