Removal candidates in patterns

Olaf Chitil O.Chitil at
Thu Jan 26 12:01:19 EST 2006

I am very please to see on the Wiki also a list of removal candidates 
and that these include n+k patterns and ~ patterns.

I'd like to add one pattern to this list of removal candiates: k 
patterns, that is, numeric literals.

Why do I want to get rid of these three patterns? Because all three 
caused me no end of trouble when implementing the program transformation 
of the Haskell tracer Hat. Hat actually still doesn't handle nested ~ 

Why are these patterns so hard to implement for Hat? Surely the Haskell 
report gives a translation into simple core Haskell. Well, Hat does not 
use this translation because it does not want to be an inefficient 
pattern matcher (leave that job to the compiler) but produce a trace of 
the Haskell program as it is written. However, both n+k and k patterns 
cause calls of functions ( (-), (==) etc) that Hat has to record in its 
trace. Also ~ patterns do not fit the simple rewriting semantics of the 
Hat trace and hence have to be recorded specially. While in simple cases 
that occur in practice it is pretty straightforward to remove n+k, k and 
~ patterns from a larger pattern while keeping the rest of the larger 
pattern intact, in the general case this is incredibly hard.

Iff n+k patterns are removed, there is little good use for k patterns 
either. Since the introduction of monadic IO the ~ pattern is hardly 
used in practice either. In all the simple cases that these three are 
currently used in practice, it is easy for the programmer to define 
their function in an alternative way.

So get rid of these three and pattern matching becomes so much more simple.


More information about the Haskell-prime mailing list