Questions tagged [path-dependent-type]
152 questions
7
votes
1 answer
In scala, how to instruct the compiler to realise the equivalence of two abstract types?
I have a simple case to test the type inference capability of scala:
trait Super1[S] {
final type Out = this.type
final val out: Out = this
}
trait Super2[S] extends Super1[S] {
final type SS = S
}
case…
![](../../users/profiles/1732418.webp)
tribbloid
- 4,823
- 10
- 46
- 81
7
votes
2 answers
Passing around path dependent type fails to retain dependent value
Consider the following:
trait Platform {
type Arch <: Architecture
def parseArch(str: String): Option[Arch]
}
object Platform {
def parse(str: String): Option[Platform] = ???
}
trait Architecture
def main() {
def exec(p: Platform)(a:…
![](../../users/profiles/3891342.webp)
Daniel Shin
- 4,246
- 25
- 47
7
votes
2 answers
Constrain function based on origin (Path Dependent type? Type Generation?)
Sorry about terrible title, not sure of a better one. Here's a gross simplification of my problem (Sorry if it seems so trivial, that it's pointless):
class RList[T](data: List[T]) {
def map[V](f: T=>V): RList[V] = ...
}
The idea of an RList…
![](../../users/profiles/377956.webp)
Heptic
- 2,806
- 4
- 26
- 48
6
votes
1 answer
Overriding functions with path-dependent type parameters
Edit: Thanks to Derek pointing out the critical part of the error message, I was able to extract the critical part a bit more and it seems to be about Existential Types. If I do understand §3.2.10 Existential Quantification over Values in the…
![](../../users/profiles/443421.webp)
Mathias Körner
- 143
- 6
6
votes
3 answers
Splitting scalac plugin into multiple files
I'd like to split my scalac plugin into multiple files. This sounds easy but I haven't managed to pull it off due to path-dependent type issues stemming from the import global._ line.
Here's Lex Spoon's sample plugin:
package localhost
import…
![](../../users/profiles/310170.webp)
Yuvi Masory
- 2,584
- 2
- 24
- 34
6
votes
2 answers
Constraining an operation by matching a type parameter to an argument's path-dependent type
I would like to exploit Scala's type system to constrain operations in a system where there are versioned references to some values. This is all happening in some transactional context Ctx which has a version type V attached to it. Now there is a…
![](../../users/profiles/515054.webp)
0__
- 64,257
- 16
- 158
- 253
6
votes
1 answer
Surprising equivalences and non-equivalences regarding this.type
It appears to make a difference whether you refer to this.type from inside a Trait or from the scope where the object is created, with surprising results.
import scala.reflect.runtime.universe._
trait Trait {
val ttag = typeOf[this.type]
…
![](../../users/profiles/1393162.webp)
Ben Kovitz
- 4,279
- 1
- 17
- 40
6
votes
1 answer
Path-dependent types - what's wrong with the following code?
The following code:
trait Foo {
type T
val x: T
}
trait Bar {
type F <: Foo { type T <: F }
}
class C[B <: Bar](val f: B#F) {
val x: f.T = f.x
}
is rejected by the Scala compiler (2.11.5) with the following error message:
error: type…
![](../../users/profiles/2725031.webp)
Marcin Łoś
- 3,038
- 1
- 15
- 20
6
votes
2 answers
Accessing values from path-dependent type mixin
Is it possible to access values in the outer trait from an inner trait mixin? i.e.:
trait Outer {
val foo
trait Inner
}
trait InnerMixin { this: Outer#Inner =>
def bar {
// how can I access 'foo' here? smth like Outer.this.foo
…
![](../../users/profiles/1810909.webp)
eprst
- 633
- 4
- 12
6
votes
2 answers
Returning a path-dependent type from a pattern match
Given a heterogeneous type:
trait Request {
type Result
}
trait IntRequest extends Request {
type Result = Int
}
How can I make the Scala compiler happy about return a path dependent type based on a pattern match:
def test(in: Request):…
![](../../users/profiles/515054.webp)
0__
- 64,257
- 16
- 158
- 253
6
votes
2 answers
Features of different kinds of path-dependent types in scala
Suppose there is a trait:
trait OuterTrait {
type InnerType
}
Now we can write non-generic function someAlgo:
def pairToString[S, U](x: S, y: U): String =
"{" + y.toString + " in " + x.toString + "}"
def pairPrintln[S, U](x: S, y: U) {
…
![](../../users/profiles/2094474.webp)
juliet
- 193
- 6
6
votes
2 answers
Scala path dependent return type from parameter
In the following code using 2.10.0M3 in Eclipse plugin 2.1.0 for 2.10M3. I'm using the default setting which is targeting JVM 1.5
class GeomBase[T <: DTypes] {
abstract class NewObjs {
def newHex(gridR: GridBase, coodI: Cood):…
![](../../users/profiles/728790.webp)
Rich Oliver
- 5,653
- 4
- 32
- 52
5
votes
1 answer
Exposing a path-dependent type coming from a singleton type
I'm trying to make Scala find the right type for a path-dependent type coming from a singleton type.
First, here is the type container for the example, and one instance:
trait Container {
type X
def get(): X
}
val container = new Container {
…
![](../../users/profiles/1057315.webp)
betehess
- 817
- 4
- 18
5
votes
2 answers
How to import inner classes without path dependency in Scala?
TL&DR: Is it possible to (locally?) disable path-dependent typing? I'd like to issue a single import statement similar to import x._, but to make C refer to X#C rather than x.C (X being the type of x)?
I have a bunch of types:
class Button[M] { ...…
![](../../users/profiles/166235.webp)
Rotsor
- 13,009
- 5
- 40
- 57
5
votes
4 answers
How can I provide a compile-time guarantee that my method will return the same object it gets in Scala?
In a Scala class, I can conveniently declare the return type of a method to be this.type to guarantee that it will return the same object it is called on:
class Foo {
def bar: this.type = this
}
Is there a way I can similarly specify that a…
![](../../users/profiles/390581.webp)
Jean-Philippe Pellet
- 56,205
- 18
- 161
- 223