Questions tagged [path-dependent-type]
152 questions
130
votes
1 answer
What is meant by Scala's path-dependent types?
I've heard that Scala has path-dependent types. It's something to do with inner-classes but what does this actually mean and why do I care?
oxbow_lakes
- 129,207
- 53
- 306
- 443
113
votes
4 answers
Any reason why scala does not explicitly support dependent types?
There are path dependent types and I think it is possible to express almost all the features of such languages as Epigram or Agda in Scala, but I'm wondering why Scala does not support this more explicitly like it does very nicely in other areas…
Ashkan Kh. Nazary
- 20,086
- 13
- 40
- 60
19
votes
1 answer
Sample of `forSome { val `?
Scala Language Specification specifies syntax of Existential Types as
Type ::= InfixType ExistentialClauses
ExistentialClauses ::= ‘forSome’ ‘{’ ExistentialDcl
{semi ExistentialDcl} ‘}’
ExistentialDcl ::=…
Freewind
- 177,284
- 143
- 381
- 649
14
votes
3 answers
Why does Scala have path-dependent types?
I've been doing some research on path-dependent types. The best description I could find for it was:
If L is a type label, then x.L and y.L are the same type iff x and y can be shown to refer to the same object.
This sometimes isn't the subtyping…
keiter
- 3,454
- 25
- 38
13
votes
1 answer
Why can’t Scala infer the path of a path-dependent type—even from an explicit self-reference?
I'd like to pass an object to a function that accepts an argument with a projected type, and get Scala to deduce that the object's type comes from the object that encloses it. Here's some simple code to illustrate the difficulty:
trait Cult { cult_…
Ben Kovitz
- 4,279
- 1
- 17
- 40
13
votes
2 answers
Path-dependent types and nested traits
Background
Suppose I have some nested traits:
trait Foo { trait Bar }
And a couple of instances:
val myFoo = new Foo {}
val myBar = new myFoo.Bar {}
I can write the following, which look (at least at a glance) like they should do more or less the…
Travis Brown
- 135,682
- 12
- 352
- 654
12
votes
1 answer
Dependent method types conflict with default arguments
When playing with scala's dependent method types, I encountered a conflict with default method parameters:
abstract class X {
type Y
case class YY(y: Y)
}
object XX extends X {
type Y = String
}
trait SomeTrait {
def method(x: X)(y: x.YY,…
Alexander Bulaev
- 245
- 1
- 8
12
votes
1 answer
Dependent types not working for constructors?
Path-dependent types are useful:
trait Sys {
type Global
}
def foo[S <: Sys](system: S)(global: system.Global) = ()
Why doesn't this work for constructors?
class Foo[S <: Sys](val system: S)(val global: system.Global)
Or am I just doing it…
0__
- 64,257
- 16
- 158
- 253
11
votes
1 answer
scala path dependent types and type level proofs
I am currently trying to define a model of a clocked dataflow language in scala.
A flow virtually represents an infinite sequence of values of some type T, paced by some clock C (a clock indicates at which moments the flow is actually…
remi
- 526
- 3
- 12
11
votes
1 answer
What is the difference between path-dependent types and dependent types?
Scala has path-dependent types, but it is said that Scala doesn’t support dependent typing. What is the difference between path-dependent types and dependent types?
As far as I understand, path-dependent types are one kind of dependent types.
rightfold
- 30,950
- 10
- 83
- 106
9
votes
1 answer
relationship between path-dependent inner types in Scala
Warning: I'm cross-posting from #scala
The book Programming in Scala states that path-dependent types are different depending on the exact instance of the path in question. If so, I don't understand why all the following predicates return…
Yuvi Masory
- 2,584
- 2
- 24
- 34
9
votes
1 answer
Map with path-dependent value type?
I know that Scala has path-dependent types, so for example if I have a class within an inner class I can constrain one argument of a method to be an instance of the inner class of the other argument:
class Outer { class Inner( x:Int ) }
val o1 = new…
AmigoNico
- 6,142
- 1
- 30
- 43
8
votes
2 answers
How to emulate a dependent type in Scala
I'm trying to define a generic residue class ring in Scala. A residue class ring is defined by some base ring (e.g. the integers) and a modulus (e.g. two), which is a value from the base ring. Both rings and their elements are objects, hence the…
starblue
- 51,675
- 14
- 88
- 146
8
votes
1 answer
How do I encode this method with an implicit parameter group which contains a dependent type?
Given a typeclass Printer with a dependent type Show[A]:
trait Printer {
type Show[A]
def show[A](x: A)(implicit z: Show[A]): String
}
object Printer {
// the intent here is this is the dumb fallback
// and a user can have a better…
Dale Wijnand
- 5,854
- 4
- 25
- 53
8
votes
1 answer
Are path-dependent types type projections?
I'm reading Scala in depth now. Here is an excerpt from the book:
All path-dependent types are type projections. A path-dependent type foo.Bar is rewritten
as foo.type#Bar by the compiler...
In Scala, all type references can be written as…
4e6
- 10,398
- 4
- 46
- 57