Sun Mar 14 21:47:37 CET 2010

Haskell vs. Scheme

One problem I haven't found a solution for in Haskell is the
specification of pattern matching rules.

In the Scheme implementation of Staapl there are rule templates that
can be expanded into rule instances.  Macros make this easy.

      (word         opcode)
      ((1+          incf)
       (1-          decf)
       (rot<<c      rlcf)
       (rot>>c      rrcf)
       (rot<<       rlncf)
       (rot>>       rrncf)
       (swap-nibble swapf))
      (([movf f 0 0] word) ([opcode f 0 0]))
      ((word)              ([opcode WREG 0 0])))

Above the identifiers `1+',`1-',... are defined by instantiating the
two rules on the bottom, filling in `word' and `opcode' respectively.

I'd say the problem with Haskell is that pattern matching is syntactic
sugar, and syntactic abstraction is not easy (without resorting to
template Haskell).

So the question is, can pattern matching be solved in a different way
as to restore compositionality?

Maybe the answer is in expressing the redundancy differently?
I.e. instead of having to resort to code that generates pattern
matching rules for a data type, make the data type more general so a
non-redundant set of rules can capture the ``for these do'' part.