Destructuring and Pattern Matching in various FP languages.
-
Most functional programming languages provide some level of de-structuring. Destructuring gives you a short-hand way of naming and getting the innards of the structure.
-
The difference between destructuring and pattern matching is that in Pattern matching, we are not only matching on relative positions of elements in the data-structure, but also trying to dispatch to different definitions based on the value inside the data structure. This dispatch is a kind of conditional construct, while in destructuring there is nothing conditional about it. So, Pattern matching is about associating a definition with a particular set of inputs. So, for the same function, we can have many such definitions for inputs that we destructure on.
This is an elaboration of one of the melodies that Ryan Lemmer and myself prepared for the Code Jugalbandi - http://codejugalbandi.org. You can download this Jugalbandi CodeJugalbandi-Destructuring-PatternMatching-HealthyCode#Apr2015.pdf (it appeared in the Healthy Code Magazine in April 2015.