Questions tagged [path-dependent-type]

152 questions
4
votes
3 answers

Is a Path Dependent Type a subtype?

trait A { trait B { def foo: A.this.B = new B{} def bar: A#B = foo def baz: A.this.B = bar // type mismatch; found : A#B required: A.this.B } } Am I right that A.this.B is a path dependent type?! (That's my understanding so…
Peter Schmitz
  • 5,734
  • 4
  • 24
  • 48
4
votes
3 answers

Driving a singleton type through a brickwall

Here is a very condensed version: case class Brickwall[A](otherSide: A) trait Monoman { def me(m: this.type): Unit } def test(m: Monoman): Unit = m.me(Brickwall(m).otherSide) -> error: type mismatch; found : Monoman required: m.type stupid…
0__
  • 64,257
  • 16
  • 158
  • 253
4
votes
2 answers

Scala Dependent type does not compile

This code should compile in Scala: trait Pipe { type Input type Output def apply(input: Input): Output } object Pipe { trait Start extends Pipe { override type Input = Seq[String] } abstract class Connect(val prev: Pipe) extends…
pathikrit
  • 29,060
  • 33
  • 127
  • 206
4
votes
1 answer

How to use path-dependent types with type classes in Scala

I’m having some problems with path dependent types. I have some types Foo with an abstract type member F. Instances such as Bar will provide the concrete type. Then there is a type class Baz. I have instances of the type class for each concrete type…
steinybot
  • 3,745
  • 5
  • 28
  • 43
4
votes
1 answer

Objects with type members: what is Scala's object vs module system ? (Trying to understand a 2014 Odersky paper on path dependent types)

I am reading Foundations of path dependent types. On the first page, on the right column it is written: Our motivation is twofold. First, we believe objects with type members are not fully understood. It is not clear what causes the complexity, …
jhegedus
  • 18,516
  • 11
  • 84
  • 147
4
votes
1 answer

In Scala, how can I restrict multiple parameters must be a type inside the same type?

I'm trying to use path dependent type with generics. I have two classes, the class C2 is nested in C1. case class C1(v1: Int) { case class C2(v2: Int) } And I have two object of class C1 here: object O1 extends C1(1) object O2 extends C1(2) I…
lxohi
  • 320
  • 2
  • 11
4
votes
2 answers

Scala: implicit lookup of type class instance for path-dependent type

trait Encoder[From, To] { def encode(x: From): To } object Encoder { implicit val thingToString: Encoder[Thing, String] = new Encoder[Thing, String] { def encode(x: Thing): String = x.toString } } trait Config { type Repr } class…
Chris B
  • 8,939
  • 4
  • 30
  • 36
4
votes
2 answers

Path-dependent typing over match/case

sealed trait Desc { type T } trait Dataset[A] { def toDS[A] = new Dataset[A] {} } trait DataFrame {} sealed trait DFDesc extends Desc { type T = Dummy } sealed trait DSDesc[A] extends Desc { type T = A } trait JobConstruction { def…
Reactormonk
  • 20,410
  • 12
  • 66
  • 110
4
votes
1 answer

Composing type-level functions with implicit witnesses

I am experimenting with some rather complex type-level calculations. There, I have some type tags (say, A, B, and C), and functions working on them, which are represented by implicit witnesses with path-dependent result types: class A class B class…
4
votes
1 answer

Type mismatch with type projection

I'm having a compiler type mismatch error that I do not understand. Given the following definition of an Elem and a factory (Companion): object Elem { trait Companion[E[~] <: Elem[~]] { def apply[S](peer: E[S]#Peer): E[S] // wrap a peer in its…
0__
  • 64,257
  • 16
  • 158
  • 253
4
votes
1 answer

Unable to resolve path dependent type class evidence w/o having value type accessible

I got stuck for like an hour to discover this fact: class Foo { trait TypeClass[X] object TypeClass { implicit val gimme = new TypeClass[Int]{} } def foo[X : TypeClass](p: X): Unit = println("yeah " + p) } // compiles val foo =…
lisak
  • 20,109
  • 39
  • 146
  • 236
4
votes
1 answer

Deep conversion of Map to TreeMap

I need to convert arbitrary nested Map to TreeMap. Examples: Map[Int, String] -> TreeMap[Int, String] Map[Int, Map[Int, String]] -> TreeMap[Int, TreeMap[Int, String]] ... etc I've got working solution with type gymnastics and implicit conversions,…
4
votes
2 answers

Why scala compiler doesn't infer type with abstract type

Given the following code trait A { type B } case class C extends A { type B = String } def f[V <: A](b: V#B => V) = b This one compile f[C](a => new C()) But why this one doesn't compile ? f(a => new C())
Yann Moisan
  • 7,685
  • 6
  • 35
  • 83
4
votes
1 answer

Implicit conversions for members that are types

given: implicit class WithRetType[T, U](x: T => U) { type Ret = U } this: val foo = (_: Int) * 2 val x: foo.Ret = 3 yields: error: type Ret is not a member of Int => Int val x: foo.Ret = ??? ^ the following however works: val foo =…
Erik Kaplun
  • 33,421
  • 12
  • 92
  • 102
4
votes
1 answer

Chaining path-dependent types and instantiating them when they having different parameter lists in Scala

I'm experimenting with writing more statically type-safe code by implementing a simple card game. In this game, there are several unique cards and each card has a card-specific effect which may require additional parameters (e.g., a target for the…