Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Scala only language with overloaded extractors?

In at least some of the ML family languages, you can define records on which you can perform pattern matching e.g. http://learnyouahaskell.com/making-our-own-types-and-typeclasses - the basic idea is that you define a record type with named fields, a constructor is automatically created with those fields as parameters so you can create records of that type, and an extractor is automatically created with those fields as parameters so you can pattern match on records of that type.

Scala goes a step further and allows the fields stored in the record, the constructor parameters and the extractor parameters to be decoupled from each other e.g. http://daily-scala.blogspot.com/2009/11/overloaded-unapply.html - in this it is living up to its goal of supporting both object-oriented and functional programming. (Object-oriented languages of course normally allow stored fields and constructor parameters to be decoupled, though they don't normally have extractors.)

Are there any other languages that have pattern matching and allow such decoupling?

Has anything been written about the pros and cons of such decoupling?

like image 200
rwallace Avatar asked May 12 '12 01:05

rwallace


1 Answers

I admit that I don't have 100% of the background required to understand your question, but I can say that F# has a feature called "Active Patterns" that it seems could be used to build the same functionality that your daily-scala link demonstrates.

Is that in the neighborhood of what you're looking for?

like image 120
sblom Avatar answered Nov 01 '22 20:11

sblom