Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Activity
  • Nov 26 18:51
    som-snytt labeled #12501
  • Nov 26 18:21
    som-snytt opened #12501
  • Nov 26 16:02
    arata-honda synchronize #2235
  • Nov 26 01:08
    arata-honda synchronize #2235
  • Nov 26 01:02
    arata-honda commented #2235
  • Nov 26 00:59
    arata-honda commented #2235
  • Nov 26 00:58
    arata-honda synchronize #2235
  • Nov 25 20:58
    joshlemer commented #1256
  • Nov 25 18:04
    eed3si9n commented #2235
  • Nov 25 17:58
    joshlemer commented #1256
  • Nov 25 17:53
    joshlemer closed #1306
  • Nov 25 17:53
    joshlemer commented #1306
  • Nov 25 17:50
    joshlemer commented #1306
  • Nov 25 17:49
    joshlemer labeled #1306
  • Nov 25 17:49
    joshlemer opened #1306
  • Nov 25 15:12
    SethTisue unlabeled #9814
  • Nov 25 15:12
    SethTisue labeled #9814
  • Nov 25 10:55
    olafurpg commented #12500
  • Nov 25 10:54
    olafurpg commented #12500
  • Nov 25 10:38
    lrytz commented #9807
Fabio Epifani
@epifab
yes I thought so :)
heksesang
@heksenlied:matrix.org
[m]
@prolativ: Thanks! I will try to see if I do something similar to what you did, if I can extract a more exact error. 🙂
@epifab: Unsure why, but it obviously doesn't interpret the type as "yo" (as manually specifying that type makes it work). But I do mean to recall there has been such a problem mentioned somewhere (some issue on the tracker?) where one had to store things in a val and pass that val to the method for it to type it correctly.
Fabio Epifani
@epifab
@heksenlied:matrix.org yeah, something definitely wrong there. I opened a bug lampepfl/dotty#12583
heksesang
@heksenlied:matrix.org
[m]
The problem that happens is that A in Wrapper is somehow being "altered" by test, which makes summoning ValueOf[A] fails. What seems to also work is moving the using-clause to test, so it obviously is a case of the test-method making the parameter less specific.
Michał Pałka
@prolativ

test(Wrapper("yo")) works if you redefine Wrapper as

case class Wrapper[A <: Singleton](a: A)

so it looks like using ValueOf[A] is the problem here, not Singleton itself

heksesang
@heksenlied:matrix.org
[m]
Yeah, the type of A within test doesn't resolve to "yo", I guess it resolves to String & Singleton instead.
Which means that, yes, it's a singleton, but there is no way to summon a ValueOf for it.
Michał Pałka
@prolativ
This works
case class Wrapper[A <: Singleton](a: A)(using ValueOf[a.type])

def test[A <: Singleton](blabla: Wrapper[A]): Unit = ()

test(Wrapper("yo"))
Fabio Epifani
@epifab
yeah, something is wrong with the type inference. I also just tested it in Scala 2, and this is a regression
it's interesting that this last example works. I think it defeats my understanding of Singleton
Vojtech Letal
@letalvoj

Please, anyone has a quick hint on how to replicate the three lines of scala2 in scala3? 🙏🏻

I will try to give a more specific example. I would like to have an Expr[CC] which is equivalent to instantiating a new instance of CC, yet generic.

    case class CC(i:Int)
    val expected = '{ new CC(1) }

Attempts to generalize that:

    val ts = TypeRepr.of[CC] // or Type[CC] ...
    val attempt1 = '{new ts(1)} // something as simple as this fails
    val attempt2 = Apply(
      Select.unique(New(Ident(TermRef(ts,"???"))),"<init>"),
      List(Literal(IntConstant(1)))
    ).asExprOf[CC] // I have no idea how to instantiate this
Pls, any chance I can create a quote equivalent to instantiating a new class, given I have
  • the necessary constructor parameters (List[Expr[_]])
  • type of the class (Type[CC])
    ? 🙏🏻
Swoorup Joshi
@Swoorup
is there a way to make this tail recursive?
def findGapsForSorted(x: List[Int]): List[Tuple2[Int, Int]] = 
  def solveFor(xs: List[Int]): List[Tuple2[Int, Int]] =
    val midpoint = xs.length/2
    if xs.length > 2 then 
      val first = xs.head
      val last = xs.last
      if (first + xs.length - 1 >= last)
        then List((first, last))
      else 
        solveFor(xs.slice(0, midpoint)) ++ 
        solveFor(xs.slice(midpoint, xs.length))
    else
      xs match 
        case Nil => List.empty
        case List(one) => List((one, one))
        case start :: end :: Nil => 
          if (start + 1) >= end 
          then List((start, end))
          else List((start, start), (end, end))
        case _ => ???

  solveFor(x)
    .foldLeft(List.empty) { (state, el) => 
      state match 
        case h :+ (start, end) if end + 1 == el._1 => h :+ (start, el._2)
        case xs => xs :+ el
    }
Rob Norris
@tpolecat
Yes, but it's probably not worth it. Stack depth is on the order of log2(xs.length) which can never be larger than 32.
However you're doing a lot of O(N) operations here (.length, ++, :+) that might make this routine slow for large inputs.
Graham Brown
@geronimus

Hello there!

Is there some way to get at an object's runtime TypeTag in Scala 3?

(I'm not using macros. I just want to output it, in order to provide a helpful message in some unit tests.)

Is it safe to add the 2.13 version of the scala-reflect API to my libraryDependencies with cross-compilation?

Or is there a better way of doing this in Scala 3?

Rob Norris
@tpolecat
You just want the name of a type for diagnostic purposes?
Graham Brown
@geronimus
Yes, that's it!
Rob Norris
@tpolecat
This may do what you want https://github.com/tpolecat/typename
It works in Scala 2 and3
"Works", I should say.
Graham Brown
@geronimus
Magnificent! Thank you!
Rob Norris
@tpolecat
Getting the string representation for a type is a longstanding and super irritating problem in Scala and it has no general solution as far as I know. Many people have told me "oh that should be easy" but it's not.
OlegYch
@OlegYch
Swoorup Joshi
@Swoorup
@tpolecat that means I would probably have to use arrays along with tailrecursion
Graham Brown
@geronimus
Thanks @tpolecat and @OlegYch ! This solves my immediate problem and also makes for a lot of interesting reading.
Rob Norris
@tpolecat
I'm getting a NoSuchMethodError trying to call this Java method https://github.com/testcontainers/testcontainers-java/blob/8965712f239ae3c449cec579264af5e79265f314/core/src/main/java/org/testcontainers/images/builder/traits/ClasspathTrait.java#L13 from Scala 3. @smarter is there anything about this Java type that makes you suspicious?
It works fine when called from Scala 2.11/12/13
Luis Miguel Mejía Suárez
@BalmungSan
Maybe something related to the F-Bound?
shvahabi
@shvahabi:matrix.org
[m]

Is xml string interpolation implemented as a feature of Scala 3 ? If positive, how can I make

xml"""
         |<p>Hello World!</p>
         |""".stripMargin

compile? I always receive a value xml is not a member of StringContext error message.

Luis Miguel Mejía Suárez
@BalmungSan
AFAIK xml support is not part of the compiler anymore.
If such interpolator exists it should be part of some library, maybe this one: https://github.com/scala/scala-xml
1 reply
shvahabi
@shvahabi:matrix.org
[m]
is the sample code for xml interpolation at https://dotty.epfl.ch/docs/reference/dropped-features/xml.html compilable in anyway?
Luis Miguel Mejía Suárez
@BalmungSan
It seems the Scala 3 docs are still at RC1
Uhm, I hope the will update them soon.
Tom Grigg
@griggt
@BalmungSan 3.0.1-RC1, not 3.0.0-RC1
Luis Miguel Mejía Suárez
@BalmungSan
ups
But that import doesn't work on 3.0.0 so maybe it was just added?
Tom Grigg
@griggt
the docs for 3.0.0 are not online afaik
Luis Miguel Mejía Suárez
@BalmungSan
Ah it is another library @shvahabi:matrix.org https://github.com/lampepfl/xml-interpolator
Tom Grigg
@griggt
jinx
shvahabi
@shvahabi:matrix.org
[m]
Thanks @griggt and @BalmungSan it seems to be the right answer. But that library seems neither have a release nor being published to scaladex. How can I add it as a dependency? Any solution other than an unmanaged dependency in lib folder?
It also is not available under dotty here https://dotty.epfl.ch/api/index.html
Luis Miguel Mejía Suárez
@BalmungSan
@shvahabi:matrix.org lampepfl/xml-interpolator#17
1 reply
It seems that repo is just a PoC (that apparently was successful)
So the final results should be merged into scala-xml and published soon.
As of today, it seems there is not easy way of using it.
You may want to pop up in that issue and show interest in it being merged.