!amEFGYrRomMpJtiMDK:matrix.org

Scala Metaprogramming

243 Members
3 Servers

Load older messages


SenderMessageTime
26 May 2022
@blast_hardcheese:matrix.orgblast_hardcheeseI'll give it a shot if you think it'd help15:02:18
@blast_hardcheese:matrix.orgblast_hardcheese The reified there is a reference to the TypeTag of the loaded class, if it's also the name of a library I've not used that 15:04:29
@_discord_192322936219238400:t2bot.ioAly Ah I see 15:04:47
@_discord_192322936219238400:t2bot.ioAly Yeah, so then my thought would be =:= would be what you want 15:05:13
@_discord_192322936219238400:t2bot.ioAly those reifieds should be =:= to your tts if the Ls reference the same type 15:05:34
@blast_hardcheese:matrix.orgblast_hardcheese _.reified is the tt, so .filter(_.reified =:= tt) 15:06:32
@blast_hardcheese:matrix.orgblast_hardcheeseGiving an infant a bottle currently, but I'll try it shortly15:06:52
@blast_hardcheese:matrix.orgblast_hardcheese Right -- =:= is a binary type-level operator, not much that can be done with values unless I'm missing something 15:50:20
@_discord_192322936219238400:t2bot.ioAly =:= should be a function on type tags 15:51:17
@_discord_192322936219238400:t2bot.ioAly it should be runnable on a type tag value 15:51:23
@blast_hardcheese:matrix.orgblast_hardcheese
15:51:32
@blast_hardcheese:matrix.orgblast_hardcheese *
[error] .../guardrail/modules/core/src/main/scala/dev/guardrail/generators/spi/ClientGeneratorLoader.scala:23:25: value =:= is not a member of reflect.runtime.universe.TypeTag[dev.guardrail.Target[x$1.L]]
[error]       .filter(_.reified =:= tt)
[error]                         ^

15:51:46
@blast_hardcheese:matrix.orgblast_hardcheese *
[error] .../guardrail/modules/core/src/main/scala/dev/guardrail/generators/spi/ClientGeneratorLoader.scala:23:25: value =:= is not a member of reflect.runtime.universe.TypeTag[dev.guardrail.Target[x$1.L]]
[error]       .filter(_.reified =:= tt)
[error]                         ^
15:51:50
@blast_hardcheese:matrix.orgblast_hardcheeseperhaps I'm missing an import?15:51:54
@_discord_192322936219238400:t2bot.ioAly import reflect.runtime.universe._ is what Seth used 15:52:07
@_discord_192322936219238400:t2bot.ioAly so yes it seems you would be 15:52:18
@blast_hardcheese:matrix.orgblast_hardcheeseeven with that import I get the same message. Let me try on 2.1315:52:45
@blast_hardcheese:matrix.orgblast_hardcheeseI'm on 2.1215:52:47
@blast_hardcheese:matrix.orgblast_hardcheese

nah, 2.13 has the same compiler error.

Poking around in scalac suggests that I needed to TypeTag#tpe in order to get =:=, and that it's just a normal member, so in case others are following along and are curious, that was my issue. Running tests now to see if that does what I expect

16:01:48
@blast_hardcheese:matrix.orgblast_hardcheesepromising though16:02:00
@blast_hardcheese:matrix.orgblast_hardcheesewao, it actually seems to work, turns out Seth knows a thing or two about the compiler after all! 😜16:04:02
@blast_hardcheese:matrix.orgblast_hardcheeseThank you both!16:04:17
@_discord_192322936219238400:t2bot.ioAly oh it is .tpe 16:08:32
@_discord_192322936219238400:t2bot.ioAly I should have noticed, oops 😅 16:08:39
@_discord_192322936219238400:t2bot.ioAly Nice! 16:08:40
@blast_hardcheese:matrix.orgblast_hardcheese I had never used =:= in a value context before, so this is all very new to me 16:27:49
@blast_hardcheese:matrix.orgblast_hardcheeseI've been privileged by my genericism being in the type level16:28:32
@_discord_645109735200129024:t2bot.iogregghz#4671 Hey all, I'm trying to learn scala 3 macros and need some help with implementing polymorphic methods. I've created a macro that takes a type parameter (referencing a trait) and attempts to create an implementation of that trait.

That is, calling: make[TestTrait] should produce a class that implements TestTrait. However, so far, I am unable to implement polymorphic methods. TestTrait has this abstract method: def poly[A](x: List[A]): A and I want the implementation created via the macro to just call x.head.

My attempt at this is here: https://gist.github.com/gregghz/6b74e50c1600c30322403449ce978a8c

The code produced looks how I'd expect/want with a class defined and an override for poly that looks like this:

override def poly[A](x: scala.collection.immutable.List[A]): A = x.head


However, the compilation fails with an error saying that my class needs to be abstract because poly is no defined. The error says that my override does not match because their type parameters differ even though the compiler output shows them side by side and they look identical:

[error]   |(Note that
[error]   | parameter List[A] in def poly[A](x: List[A]): A in trait TestTrait in package macros does not match
[error]   | parameter List[A] in def poly[A](x: List[A]): A in class ImplT
[error]   | their type parameters differ)


Can anyone point me in the right direction here?
17:31:52
@_discord_645109735200129024:t2bot.iogregghz#4671 * Hey all, I'm trying to learn scala 3 macros and need some help with implementing polymorphic methods. I've created a macro that takes a type parameter (referencing a trait) and attempts to create an implementation of that trait.

That is, calling: make[TestTrait] should produce a class that implements TestTrait. However, so far, I am unable to implement polymorphic methods. TestTrait has this abstract method: def poly[A](x: List[A]): A and I want the implementation created via the macro to just call x.head.

My attempt at this is here: https://gist.github.com/gregghz/6b74e50c1600c30322403449ce978a8c

The code produced looks how I'd expect/want with a class defined and an override for poly that looks like this:

def poly[A](x: scala.collection.immutable.List[A]): A = x.head


However, the compilation fails with an error saying that my class needs to be abstract because poly is no defined. The error says that my override does not match because their type parameters differ even though the compiler output shows them side by side and they look identical:

[error]   |(Note that
[error]   | parameter List[A] in def poly[A](x: List[A]): A in trait TestTrait in package macros does not match
[error]   | parameter List[A] in def poly[A](x: List[A]): A in class ImplT
[error]   | their type parameters differ)


Can anyone point me in the right direction here?
17:32:30
@_discord_645109735200129024:t2bot.iogregghz#4671 * Hey all, I'm trying to learn scala 3 macros and need some help with implementing polymorphic methods. I've created a macro that takes a type parameter (referencing a trait) and attempts to create an implementation of that trait.

That is, calling: make[TestTrait] should produce a class that implements TestTrait. However, so far, I am unable to implement polymorphic methods. TestTrait has this abstract method: def poly[A](x: List[A]): A and I want the implementation created via the macro to just call x.head.

My attempt at this is here: https://gist.github.com/gregghz/6b74e50c1600c30322403449ce978a8c

The code produced looks how I'd expect/want with a class defined and an override for poly that looks like this:

def poly[A](x: scala.collection.immutable.List[A]): A = x.head


However, the compilation fails with an error saying that my class needs to be abstract because poly is not defined. The error says that my override does not match because their type parameters differ even though the compiler output shows them side by side and they look identical:

[error]   |(Note that
[error]   | parameter List[A] in def poly[A](x: List[A]): A in trait TestTrait in package macros does not match
[error]   | parameter List[A] in def poly[A](x: List[A]): A in class ImplT
[error]   | their type parameters differ)


Can anyone point me in the right direction here?
17:32:57

There are no newer messages yet.


Back to Room List