In at least some languages of the ML family, you can define records in which you can perform pattern matching, for example. http://learnyouahaskell.com/making-our-own-types-and-typeclasses - the main idea is that you determine the type of record with named fields, a constructor is automatically created with these fields as parameters so that you can create records of this type, and an extractor is automatically created with these fields as parameters so that you can match patterns in records of this type.
Scala goes even further and allows you to separate the fields stored in the record, constructor parameters and extractor parameters from each other, for example, http://daily-scala.blogspot.com/2009/11/overloaded-unapply.html - this corresponds to its goal of supporting both object-oriented and functional programming. (Object-oriented languages, of course, usually allow you to separate stored fields and constructor parameters, although they usually do not have extractors.)
Are there any other languages that match the patterns and allow such a denouement?
Has it been written about the pros and cons of this unleashing?
source
share