Pattern matching and path dependent types

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

Pattern matching and path dependent types

Pavel Perikov
It seem like pattern matching looses type information. I can't instantly say if this a fundamental limitation or the implementation limitation. Can anyone with better understanding of Scala's type system comment on this?

The code is on gist: https://gist.github.com/p-pavel/24e63bb9f40ea95fd988787a35ad4d80 :

trait A {
type T
val t : T
}
object A {
def unapply(arg: A): Option[arg.T] = Some(arg.t)
}
def use(a : A) = a match {
case A(t)
val s: a.T = t // type mismatch.
// found t.type (with underlying type <unapply-selector>.T)
// required: a.T
}

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.
Reply | Threaded
Open this post in threaded view
|

Re: Pattern matching and path dependent types

martin odersky-2
It looks very reasonable to recover that type information. However, it would need a particular rule in the specification and implementation of pattern matching. A priori, there is no relationship specified between the selector `a` and the result of the unapply. This would be something worthwhile to work on, generally pattern matching is still too underspecified.

 - Martin


On Thu, Feb 23, 2017 at 1:47 PM, Pavel Perikov <[hidden email]> wrote:
It seem like pattern matching looses type information. I can't instantly say if this a fundamental limitation or the implementation limitation. Can anyone with better understanding of Scala's type system comment on this?

The code is on gist: https://gist.github.com/p-pavel/24e63bb9f40ea95fd988787a35ad4d80 :

trait A {
type T
val t : T
}
object A {
def unapply(arg: A): Option[arg.T] = Some(arg.t)
}
def use(a : A) = a match {
case A(t)
val s: a.T = t // type mismatch.
// found t.type (with underlying type <unapply-selector>.T)
// required: a.T
}

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.



--

Martin Odersky
EPFL and Lightbend

--
You received this message because you are subscribed to the Google Groups "scala-user" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [hidden email].
For more options, visit https://groups.google.com/d/optout.