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
3
votes
2 answers

Can't use flatMap as an extension method on a self-written instance of a monad

I've tried to use flatMap on WriterT and it was successful. So the problem is with my type probably but I can't find what's wrong with it. import cats.Monad import cats.syntax.flatMap._ object Main extends App { type Optional[A] = A | Null …
Awethon
  • 144
  • 1
  • 9
3
votes
2 answers

scala3 extension method type parameter

this is a direct translation of my scala2 code to scala3 trait Narrow[F[_], A, B <: A: ClassTag]: def apply(fa: F[A]): F[B] extension [F[_], A] (fa: F[A]): def narrow[B: ClassTag] (using op: Narrow[F, A, B]): F[B] = op(fa) I need to specify…
aepurniet
  • 1,719
  • 16
  • 24
3
votes
1 answer

Dependent tuples in Scala 3 / Dotty

I'm trying to encode a dependent map using a list of dependent tuples. Here is what I have that does not work: class DTuple[Key, ValueMap[_ <: Key]](val first: Key)(val second: ValueMap[first.type]) type DKey = "Tag" | "Versions" | "Author" …
Mikaël Mayer
  • 10,425
  • 6
  • 64
  • 101
3
votes
1 answer

Do volatile types still exist in Scala 3?

I can't find the equivalent SLS for Scala 3. I am trying to slowly get myself into the Scala 3 mindset and write new code - and refactor old when next changed - so that its translation to Scala 3 is straightforward. Certain current usecases of type…
Turin
  • 2,208
  • 15
  • 23
3
votes
1 answer

Extension vs infix trait methods for Dotty Type Classes

I went through the documentation and found a couple of ways how to define ad-hoc behavior for type class instances. Here's the original example: trait Ord[T] { def compare(x: T, y: T): Int extension (x: T) def < (y: T) = compare(x, y) < 0 …
ppopoff
  • 658
  • 7
  • 17
3
votes
1 answer

Structural types in Dotty/Scala 3 compiled failed?

I tested the following code of structural type: trait Data object Main { def main(args: Array[String]): Unit = { val data = new Data { val value: Int = 1 } println(data.value) } } It compiled successfully in Scala 2.13.2…
xiagao1982
  • 1,077
  • 1
  • 13
  • 25
3
votes
3 answers

How to combine two tuples with compatible types?

Suppose I have two tuples, the first is a tuple of values with type (V1, V2, .., Vn), the second is a tuple of functions with type (V1 => V1, V2 => V2, .., Vn => Vn). Now I want to combine the two tuples as (f1(v1), v2(v2), .., fn(vn)) with type…
esse
  • 1,415
  • 5
  • 10
3
votes
3 answers

How to use given in Dotty?

I was looking at Dotty docs under Contextual Abstractions page and I saw the Given Instances. Given instances (or, simply, "givens") define "canonical" values of certain types that serve for synthesizing arguments to given clauses. …
amer
  • 1,528
  • 1
  • 14
  • 22
3
votes
0 answers

Scala Play with Dotty

I've been having a look on how to get existing projects to use the Dotty compiler. This has been straightforward for small projects following this. https://github.com/lampepfl/dotty-example-project This sets the scala version to 0.2.x. Which would…
Oliver Shaw
  • 5,235
  • 4
  • 26
  • 35
3
votes
1 answer

How to use dotty in scala project?

I am working on a Scala project that I run using sbt. I want to use union types which is provided by dotty. I am having trouble in using dotty in my project. I did this: Added ./projects/plugins.sbt and ./projects/build.properties with content as…
vinayawsm
  • 845
  • 9
  • 28
3
votes
2 answers

Scala Dotty Union Type DaysOfTheWeek Example

The official Scala Dotty team showed this example from (https://d-d.me/talks/scalaworld2015/#/12) object DaysOfTheWeek { object Mon object Tue object Wed object Thu object Fri object Sat object Sun type Weekend = Sat.type |…
clay
  • 18,138
  • 28
  • 107
  • 192
2
votes
1 answer

In Scala 3, how to replace General Type Projection that has been dropped?

This code does not compile in Scala 3 since type projection on an abstract type is now invalid: trait Entity: type Key type Dictionary[T <: Entity] = Map[T#Key, T] The compiler complains that T is abstract and type projection is therefore no…
2
votes
1 answer

Scala 3 Tasty Reflection Macro: CyclicReference

I'm trying to access the parameters of a method that is being implemented as a macro. object Macros { def impl()(using Quotes): Expr[Unit] = { import quotes.reflect._ val params: List[List[ValDef]] = { def…
francoisr
  • 4,407
  • 1
  • 28
  • 48
2
votes
1 answer

Is it possible to wrap the members types with another type in Scala 3 similar to typescript mapped types?

In typescript it looks like this type Option = {some: T} | 'none' type Optional = { [P in keyof T]: Option }; type Foo = {x: string, y: number} type OptionalFoo = Optional const foo: OptionalFoo = {x: 'none', y : {some:…
ais
  • 2,514
  • 2
  • 17
  • 24
2
votes
0 answers

dotty / scala3 unmap a mapped tuple type to its constituent types

im having trouble unmapping a mapped tuple to its constituent types. How can i implement the read method of Impl[T] in a typesafe way? currently I am just doing it with Tuple.toArray / Tuple.fromArray trait Reader[A]: def read: A object…
aepurniet
  • 1,719
  • 16
  • 24