Match types matching on match types

Consider the following code:

import scala.compiletime.ops.int.*

type ASCIIInt2Char[T] = T match
  case 33 => '!'

type CharRange[T,U] = T match
  case ASCIIInt2Char[t] => T | CharRange[ASCIIInt2Char[t + 1], U]
  case U => T

Here I’m trying to build a type that represents a range of allowed characters (for example, for having a new string type like Array[Alphanumeric]). I have a table for turning an Int singleton into a Char singleton implemented as a match type, and I’d to use the inverse of that table as a match case in my CharRange match type in order to get Ints from Chars without having to implement a Char2ASCIIInt match type. Is there any plans to allow this kind of behavior in the future? Being able to match on whether T matches the result of U[t] (where U is a match type) would seemingly add a lot of power to match types.

3 Likes