I Don’t Like Data Type Pattern Matching
I have never been a big fan of algebraic data type pattern matching in functional langauges like Scala, Haskell, OCaml, and F#. I’ve always felt that because data type pattern matching relied on the structure of a data type it broke encapsulation and increased code coupling. Martin Odersky (designer of Scala) is a pretty strong advocate of data type pattern matching, and wrote this interesting article at Artima.com on the pattern matching debate. Having said that I have also felt that data type pattern matching was an important area of research and offered promise to yield powerful language features for flexible and large scale software development.
Don Syme (designer of F#) recently wrote a draft of a paper where he states “[...] it is well known that [pattern matching of algebraic data types] interacts poorly with abstraction.” which is similar to what I’ve long held. In the paper however he proposes a solution that is more abstract if you will. Perhaps data type pattern matching has hope?