Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Use TypeTags when pattern-matching otherwise erased types #6517

Open
scabug opened this issue Oct 11, 2012 · 9 comments
Open

Use TypeTags when pattern-matching otherwise erased types #6517

scabug opened this issue Oct 11, 2012 · 9 comments

Comments

@scabug
Copy link

scabug commented Oct 11, 2012

When the scrutinee of a match has a parametric type, and appropriate TypeTags are in scope, it should be possible to formulate a match like the following:

def f[T: TypeTag](x: T) = x match {
  case xs: List[String] => ...
  case xs: List[Int] => ...
}

It would be nice if that would also work with type parameters used in non-top-level positions:

def f[T: TypeTag](xs: List[T]) = xs match {
  case (s: String) :: tail =>

In principle the compiler should have all necessary knowledge available, but I cannot judge how difficult it would be to make this work.

Talking with Adriaan did not result in immediate dismissal, and he asked me to reference #5143 as related.

@scabug
Copy link
Author

scabug commented Oct 11, 2012

Imported From: https://issues.scala-lang.org/browse/SI-6517?orig=1
Reporter: @rkuhn
See #5143

@scabug
Copy link
Author

scabug commented Oct 11, 2012

@paulp said:
See also #329, which I closed as a duplicate of this, if only to be reminded about checking refinement types at runtime too.

@scabug
Copy link
Author

scabug commented Oct 11, 2012

@paulp said:
By the way, I can't tell what you want from the second example. That doesn't need to know anything about T.

@scabug
Copy link
Author

scabug commented Oct 12, 2012

@rkuhn said:
You’re right, I missed the mark slightly: make that

def f[T: TypeTag](xs: List[T]) = xs match {
  case (s: Set[String]) :: tail => ...
  case xs: List[Map[Int, Int]]  => ...
}

@scabug
Copy link
Author

scabug commented Jul 10, 2013

@adriaanm said:
Unassigning and rescheduling to M6 as previous deadline was missed.

@scabug
Copy link
Author

scabug commented Aug 28, 2016

Naftoli Gugenheim (naftoligug) said:
@roland.kuhn what do you need the first case for in your updated second example?
Also perhaps the Description should be updated

@scabug
Copy link
Author

scabug commented Mar 14, 2017

@SethTisue said:
scala/scala#5774

@scabug
Copy link
Author

scabug commented Mar 14, 2017

@milessabin said:
I don't think that PR does address this ticket, at least not directly.

@scabug
Copy link
Author

scabug commented Mar 14, 2017

@SethTisue said:
yeah, I think anyone interested in this ticket will be interested in that PR, but I've removed the "has-pull-request" tag.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant