On Sat, Jun 22, 2024 at 10:16 AM Brandon Jackson <brandonja...@gmail.com> wrote: > > > 8. Capturing values out of a pattern and binding them to variables if > > > matched > > > Ok I think that's stepping a bit far out of scope. Maybe `is` should > > > simply check and not have any side effects. > > > > As above, this is core functionality of pattern matching for ADTs, as well > > as a core feature of every other language that has pattern matching, I > > believe. It's not out of scope, it's core scope. > > Ok, it just seems like a rift between expectations and reality. When > looking at things like this, if it is not actually something that's > new to me, I like to try to put myself in the shoes of someone who it > would be new to. Why? Because there are things that you can assume a > syntax does, and there are things you would only know a syntax does by > reading the docs (if it's not buried too deeply and you can find it). > > I would never have assumed that there was a pattern to be appended to > `$foo is Bar` that would automatically assign one of its properties to > another variable if there was a match. But I guess that comes from > ignorance as I haven't had the luxury of familiarizing myself with a > language that does this. So if it is a common thing then I will chalk > it up to a bad assumption of mine.
Hi Brandon, Something doesn't sit right with me when an argument is made that something should be in this RFC because it's needed for another, future RFC (in which case, it seems like it should be part of that RFC), but in this particular case, one doesn't need to ever care about ADTs to justify binding being a part of a pattern matching RFC. Without a familiarity of the concept, I think it's very easy to view pattern matching as syntactic sugar for type or shape assertions: in other words, it simply provides another way to ensure type safety. Believe me, I've made the same mistake! Naming things is hard, and "pattern matching" as a name just intuitively feels like it should just be about the checking. But pattern matching's value is in type checking is incidental, and I think a core thing to note from the preamble of the RFC is the following: > In a sense it serves a similar purpose for complex data structures as regular > expressions do for strings. Pattern matching's core purpose is to extract data from a matched data structure, and just as regular expressions have limited value without matching groups, pattern matching is similar without binding. I think it would be difficult to think of an implementation of regular expressions without matching groups, and similarly it would be difficult to think of a useful implementation of pattern matching without the ability to extract the data from the matched data structure. Because of this, every language that implements the concept also includes binding. Hope this helps, Mark Trapp