On Sat, Jan 22, 2011 at 4:56 PM, Andre van Tonder
<andre@x> wrote:
I used to be all gung ho about pattern matching when I first encountered Scheme, until I started reading some elegant big programs in Scheme and got used to the more Schemely idiom of doing the same kind of thing, which turned out to be as readable and often a better apporoach to abstraction.
I had the same experience. However I would not dismiss the idea completely.
What I mean is that pattern matching often does not encourage good abstraction. Which of the following is the better abstracted program (independent of the underlying data type and independent of, for example, adding new fields in data types )?
(match data
((record node l r) (traverse l)
(traverse r))
((leaf x) (display x))
or
(cond ((node? data) (traverse (node-left data))
(traverse (node-right data))
((leaf? data) (display (leaf-content data))
ML or Haskell programs are chock full of the former, which looks cool exactly until they want to add an extra field to a data type and all of a sudden realize that they have to change their whole program and all programs that import the same types.