Where communities thrive


  • Join over 1.5M+ people
  • Join over 100K+ communities
  • Free without limits
  • Create your own community
People
Repo info
Activity
  • 22:26
    sjrd commented #8619
  • 22:00
    odersky synchronize #8638
  • 21:39
    odersky commented #8571
  • 21:13
    odersky assigned #8637
  • 21:11
    odersky commented #8619
  • 21:01
    odersky commented #6350
  • 20:57
    odersky commented #8638
  • 20:57
    odersky synchronize #8638
  • 20:56
    odersky edited #8638
  • 20:47
    smarter commented #8638
  • 20:45
    odersky opened #8638
  • 20:37

    bishabosha on master

    trying to rewrite typeclasses-n… Wrap the last sentence in a who… Step2: rewrite the Functor part… and 27 more (compare)

  • 20:37
    bishabosha closed #8147
  • 20:10
    julienrf assigned #8611
  • 20:10
    julienrf unassigned #8611
  • 19:58
    odersky commented #8635
  • 19:57
    odersky commented #8635
  • 19:46
    countfloyd starred lampepfl/dotty
  • 19:41
    odersky assigned #8630
  • 19:41
    odersky unassigned #8630
Olivier Blanvillain
@OlivierBlanvillain

The covariant requirement was necessary with the previous reduction. But with the new stricter overlapping checks we might be able to drop it. @OlivierBlanvillain should have a look.

I'm pretty sure none of that has changed. What example should I look at?

odersky
@odersky
The one by @noelwelsh
Noel Welsh
@noelwelsh
One attempt is here: https://gist.github.com/noelwelsh/57f7609e80fb7b752547fdd3e13f08aa
An earlier attempt is higher up in the thread :point_up: March 27, 2020 1:28 PM
Greg Zoller
@gzoller
I noticed that some collection classes scramble their class names, for example scala.collection.immutable.List -> scala.collection.immutable.$colon$colon (which, confusingly, so does Seq) Are Seq derivatives the only collections scrambled this drastically (i.e. they don't contain the class name at all)?
Guillaume Martres
@smarter
it's not List that's scrambled
:: is a subclass of List
:: is not a valid name of the JVM so it gets encoded
Sébastien Doeraene
@sjrd
Well ... actually it is a valid name on the JVM. But not in Java.
Sébastien Doeraene
@sjrd
The only characters that are not allowed on the JVM are ; / . [ (and < for method names)
Greg Zoller
@gzoller
This helps, thank you... But I'm still wondering about ::. This is "special" because its not the actual name of the class, i.e. List, or Seq. It seems most (all?) of the other encoded collection class names feature the name of the class, like Map gives you: scala.collection.immutable.Map$Map1, so the "Map" class name is clear there. Are there others that remove the class name entirely, like ::?
Sébastien Doeraene
@sjrd
It is the actual name of the case class ::, which is a subclass of List.
Greg Zoller
@gzoller
Are there others that follow that pattern?
(changing the "natural" name of the collection, e.g. List, for something more symbolic)
Michael Pilquist
@mpilquist
Some / None is a good example
Guillaume Martres
@smarter
it's not a name change
Michael Pilquist
@mpilquist
Some is to :: as Option is to List -- used as constructor and extractor and exists in same package as supertype
Greg Zoller
@gzoller
That gives me scala.Some/scala.None$, which is easy to work with. (A number of the collections encode "extra" info after the classname by mixing $... after the class)
Noel Welsh
@noelwelsh
I think the $ after a name indicates a Scala object.
name encoding is not specific to collections
Greg Zoller
@gzoller
ok
Paolo G. Giarrusso
@Blaisorblade
name encoding is one half.
Michael Pilquist
@mpilquist
Here's another example of name encoding of a class: https://www.scala-lang.org/api/current/scala/$less$colon$less.html
Paolo G. Giarrusso
@Blaisorblade
a class Foo extending Bar but not having Bar in the name is the other half...
Greg Zoller
@gzoller
? what's the other 1/2?
Paolo G. Giarrusso
@Blaisorblade
and that happens already in Java
Greg Zoller
@gzoller
yes, that's true
Paolo G. Giarrusso
@Blaisorblade
your Map$Map1 example is the special one — but that only happens because Map1 is literally nested inside Map :-)
Greg Zoller
@gzoller
that makes sense
Martijn Hoekstra
@martijnhoekstra
In an interpolation, the string parts are a Literals. The start position of the first literal is that of the opening quote, and the rest just the start of the string. I need to get the position of the start of the string, how can I determine that?
I suppose that comes down to how do I know if it's single or triple quoted
Paolo G. Giarrusso
@Blaisorblade
@martijnhoekstra are you asking about Tasty reflection or the compiler side? There’s probably a better API, but from the compiler side, Trees store their SourcePosition which stores a SourceFile so you can access the actual characters in the worst-case via https://github.com/lampepfl/dotty/blob/master/compiler/src/dotty/tools/dotc/util/SourceFile.scala#L70
(not that I’m entirely sure I get the question exactly — what you describe sounds inconsistent, possibly by oversight)
Martijn Hoekstra
@martijnhoekstra
It's on the compiler side, in the transforms on interpolators @Blaisorblade
so s"""foo $bar baz""" matches Apply(Select(Apply(StringContextApply(), List(Literals(strs))), _)
and the start positions of those strs point at the first quote and the space after $bar
oh, I can use that in a pinch, the position of f is the length of foo before the end of the first literal
should have brought my rubber duck
kerr
@hepin1989
akka/akka#28837
Akka compiles with Dotty is coming
Paolo G. Giarrusso
@Blaisorblade
Cool!
Martijn Hoekstra
@martijnhoekstra
it looks to be a bug indeed
Olivier Blanvillain
@OlivierBlanvillain
@noelwelsh @odersky So I guess the question is: would it be possible to reduce Types.IndexOf[F, Key] in the body of get? That would lead to a class cast exception. I need to modify the example a bit to show that clearly.
final case class Col[Key, Value](data: Array[Value]) 

type IndexOf[F <: Tuple, Key] <: Int =
  F match {
    case Col[Key, v] *: cols => Int
    case Col[k, v] *: cols   => String
  }

// Compiles after #8024 (it should already be possible to get there using inheritance)
def indexOf[F <: Tuple, Key](f: F, k: Key): IndexOf[F, Key] = {
  // We need some sort of ClassTag/TypeTag to properly implement this pattern matching...
  f match {
    case _: Col[Key, v] *: cols => 0
    case _: Col[k, v]   *: cols => "1"
  }
}

def get[F <: NonEmptyTuple, Key](frame: F, k: Key) =
  indexOf(frame, k)
Now if IndexOf[F, Key] reduces to String, you can get a class cast by calling get[Col[Unit] *: Unit, Unit] which returns 0 typed as a String. Similarly, if IndexOf[F, Key] reduces to Int, get[Col[Char] *: Unit, Boolean] returns "1" typed as an Int.
Paolo G. Giarrusso
@Blaisorblade
@OlivierBlanvillain but the original code is sound; if there’s a fix, it’s about https://gitter.im/lampepfl/dotty?at=5e7e01dc4a4f8e0a100bea68. In particular, here ?1 <:< Types.IndexOf[F, Key] implies ?1 = Types.IndexOf[F, Key].
sorry, that’s not true for any ?1 — but it should be true for the ?1 in question (which comes from... where, constValue ?)
Olivier Blanvillain
@OlivierBlanvillain
@Blaisorblade I see, then I think I understood the question wrong. Can the issue be minimized to use trait IndexOf[F, K] instead of a match type?
Noel Welsh
@noelwelsh

My goal is to select an element from an HList based on a type. I was using Tuple as it is an HList in Dotty, AFAIU, but that is not an essential part of the problem. In terms of implementation my approach should not be taken to be the best approach. I started looking at Dotty metaprogramming a few days ago and I'm still learning. So if there is an approach that works I'd love to hear it. A simplified version of the problem is, given,

final case class Box[Key, Value](value: Value)
val list = Box["one", Int](1) *: Box["two", Double](2.0) *: Unit

calling

get["two"](list)

should return 2.0 with type Double and

get["three"](list)

should be a compile time error. The problem is to implement get in a way that gets past type checking.

Paolo G. Giarrusso
@Blaisorblade
@OlivierBlanvillain hm, I see your point, and maybe yes? I can’t try right now.