Silly question of the day: Is there a way in #scala3 to "unpack" a String at the type level ?
ie: val x: Unpack["abc"] = ('a', 'b', 'c')
That's because I keep trying to guess at the answer without actually trying it. ;) Give me a moment...!
-
-
I tried: private def unpackImpl[S <: Singleton & String: Type](using q: Quotes): Expr[Any] = import q.reflect._ TypeRepr.of[S] match case ConstantType(StringConstant(str)) => '{ Tuple.fromArray(${Expr(str.toArray)}) } Which gives: Cyclic macro dependencies
-
The cyclic dependencies could be because you're trying to use the macro in the same file it's defined in.
- Show replies
New conversation -
-
-
The whole thing: import scala.quoted._ inline def unpack[T <: String & Singleton]: List[Char] = ${unpack[T]} def unpack[T <: String & Singleton: Type](using Quotes) = import quotes.reflect._ TypeRepr.of[T] match case ConstantType(StringConstant(s)) => Expr(s.toList)
-
Cyclic macro dependencies
(when you call it) - Show replies
New conversation -
Loading seems to be taking a while.
Twitter may be over capacity or experiencing a momentary hiccup. Try again or visit Twitter Status for more information.