Questions tagged [dotty]

Please use the [scala-3] tag for new questions about Scala 3. Dotty was a platform to try out new language concepts and compiler technologies for Scala. The theory behind these constructors is researched in DOT, a calculus for dependent object types. Most of these new technologies were incorporated into Scala 3.

Definition:

Dotty is both the name for a new compiler, as well as an umbrella term for new language concepts, that are slated to become Scala 3. The underlying theory is the calculus of dependent object types, or DOT in short. It is under active research.

Example Installation:

brew install lampepfl/brew/dotty

Important Links:

106 questions
2
votes
1 answer

How to implement typesafe domain repository in scala?

I want to implement generic and typesafe domain repository. Say I have trait Repo[Value] { def put(value: Value): Unit } case class IntRepo extends Repo[Int] { override def put(value: Int): Unit = ??? } case class StringRepo extends…
Igor Yudnikov
  • 434
  • 1
  • 6
  • 14
2
votes
2 answers

Optimizing case class use as symbols

I'm working with a Java API that passes around identifiers as strings. It seems a bit nicer to me to use typed symbols for this, so I wrote this: object Helpers { implicit def actionToString(action: Action): String = …
bbarker
  • 11,636
  • 9
  • 38
  • 62
2
votes
2 answers

How does Dotty desugar polymorphic methods?

Dotty reportedly desugars classes with type parameters to classes with type members, for example: class C[T, U] { } // <=> class C { type C$T type C$U } How does Dotty desugar polymorphic methods like in the following example? def m[T, U](x: T,…
user1804599
1
vote
1 answer

How to use macros in the Scala console?

In the Scala 3 console (or in Scastie), when running the following code: import scala.quoted._ val a = Expr("Hello") The following error results: -- Error: ---------------------------------------------------------------------- 1 |val a =…
user182917
  • 1,688
  • 2
  • 14
  • 17
1
vote
1 answer

Scala3 type matching with multiple types

I am trying to use a Scala3 type match to achieve something similar to type projections on abstract types in Scala2. A minimal example is: sealed trait Context trait AContext extends Context trait BContext extends Context trait Data[C <:…
Kieran
  • 316
  • 5
  • 15
1
vote
1 answer

How to prove that `Tuple.Map[H *: T, F] =:= (F[H] *: Tuple.Map[T, F])` in Scala 3

I'm trying to write a trait that contains given instances for a tuple type (yes I know that summonAll exists): trait TupleInstances[C[_], T <: Tuple] { val instances: Tuple.Map[T, C] } given[C[_]]: TupleInstances[C[_], EmptyTuple] with { val…
Grisu47
  • 530
  • 5
  • 16
1
vote
0 answers

How to abstract over higher-kind with F-bounded polymorphism in Scala3? The same definition works in Scala2

Assuming that several objects in Scala share an identical definition of nested generic class or trait H, with only 1 Peer type defined using F-bounded polymorphism: object Example { trait P { type H[Peer <: H[Peer]] } object P1 extends…
tribbloid
  • 4,026
  • 14
  • 64
  • 103
1
vote
1 answer

Pattern matching against union type can't remove cases from consideration

Suppose I have a type which is either a string or a tuple of strings. type OneOrTwo = String | (String, String) Now I want to discriminate between these two types. The runtime representations are distinct (String vs. Tuple), so I should be able to…
Silvio Mayolo
  • 62,821
  • 6
  • 74
  • 116
1
vote
1 answer

What is Scala 3 equivalent to this Scala 2 code that uses Enumeration and play-json?

I have some code that works in Scala 2.{10,11,12,13} that I'm now trying to convert to Scala 3. Scala 3 does Enumeration differently than Scala 2. I'm trying to figure out how to convert the following code that interacts with play-json so that it…
gknauth
  • 2,310
  • 2
  • 29
  • 44
1
vote
1 answer

Syntax for named given/using objects in Scala 3 (Dotty)

Is there a one-line way to provide a named reference to a value which is to be implicitly available (i.e. available with using syntax) without the soon-to-be-deprecated implicit keyword? According to the docs, I'd expect the following to work (under…
MSmedberg
  • 381
  • 3
  • 13
1
vote
1 answer

Printing MirroredElemTypes in Scala 3

I am trying to modify this standard example to print values with the types. And I am stuck with p.MirroredElemTypes. I haven't found any API to traverse and stringify types.
St.
  • 521
  • 3
  • 8
1
vote
1 answer

Accessing nested type parameters in Dotty Scala

I would like to do something like this with the new Scala Dotty compiler: trait Monad[M[A]] (underlyingValue:A) { def bind[A, B](f: A => M[B]): M[B] } or at least class Monad[M[A]] (underlyingValue:A) { def bind[A, B](f: A => M[B]): M[B] } but…
ameltz
  • 43
  • 6
1
vote
2 answers

Intersection types with Covariance

Consider the below: trait AA { def children: List[AA] } trait BB { def children: List[BB] } class CC extends AA, BB { override def children: List[AA] & List[BB] = ??? } When we override children in CC, the overridden method is merged…
Jatin
  • 31,116
  • 15
  • 98
  • 163
1
vote
1 answer

Scala3 macro summon typeclass instance of a TypeTree (no type arg)

trait Show[T] { def show(t: T): String } Give such Show typeclass, I want to generate show for case class like def caseClassShow[A](using Type[A], Quotes): Expr[Show[A]] = { import quotes.reflect._ def shows(caseClassExpr: Expr[A]):…
jilen
  • 5,633
  • 3
  • 35
  • 84
1
vote
1 answer

Invariant default type for enums in Scala 3

Scala 3 now has an improved way to define ADTs. A syntactic sugar that removes all the hassle of doing them with the usual sealed trait way. So I'll explain my question with an example enum Adt[+A]{ case Option1 case Option2 } In this case…
caeus
  • 3,084
  • 1
  • 22
  • 36