Matching the entire type in a match type definition

How can I match the entire type in a match type case? The following code doesn’t compile:

type MatchType[X] = X match
  case x => x

this code compiles and gives you possibility to return input type:

type MatchType[X] = X match
  case _ => X

other type transformations would need to be put before the default case.

too bad that aliases don’t work (as in normal value level match syntax), e.g.:

type MatchType[X] = X match
  case newName @ _ => newName
1 Like

Thanks! My example was too simple, I guess. Reusing the original variable doesn’t work when matching on a different type:

type MatchType[X] = MatchType2[X] match
  case ... => ...
  case x => MatchType3[x]

Yes, it would be great to have aliases.

you can probably do:

type MatchType[X] = MatchType2[X] match
  case ... => ...
  case _ => MatchType3[MatchType2[X]]

but it’s not great.

Yes, that could lead to (exponential) increase in compile-time computation.