[Pitch] is case expressions

I'm sorry for leaving you hanging for so long. The Language Steering Group talked about this proposal. We agree that there's a lot of room for improvement in this part of the language, and this specific proposal seems to be high-quality: it is thorough and well thought out. Nevertheless, we don't feel comfortable running proposals in the general space of pattern matching at the moment, because we don't feel like we have a good understanding of where the language ought to be going. We therefore want to be cautious about adding features that feel like small, incremental "wins", because we don't want to end up with three or four different features that each in isolation make some specific use case easier but which collectively don't work as a cohesive whole.

Ultimately, we'd like to have a vision document for the future of pattern matching in Swift. Right now, we're not looking to invite anyone to write that document, but we'd be very interested in having a long-running conversation about it, ideally covering a number of different questions in the area:

  • a lightweight way to check whether an enum value is in a particular case (maybe like this, or maybe with a member syntax)
  • the above, but allowing the extraction of the case's payload
  • the above, but allowing a match against an arbitrary pattern
  • whether bindings can be supported in such patterns
  • whether we can/should improve pattern syntax in general, e.g. to avoid case let
  • some equivalent to KeyPaths for enum cases
  • some surfacing of enum cases in normal KeyPaths (presumably with optional type)
  • whether any of these are reasonable to address just with macros
  • probably other things that don't come to mind immediately

We're not saying that all of these need to be addressed by a single proposal! And maybe it's okay to say that some of them aren't worth adding new features for and should just be done with switch. But we don't feel like we've seen enough discussion which takes on these issues holistically.

Therefore, we'd like to invite interested folks to start a new discussion thread about pattern matching in general.

34 Likes