[clean-list] Pattern matching

Fergus Henderson fjh@cs.mu.OZ.AU
Mon, 6 Jan 2003 03:37:45 +1100


On 04-Jan-2003, Diederik van Arkel <dvanarkel@mac.com> wrote:
> 
> On Saturday, January 4, 2003, at 09:30 AM, Dmitry Malenko wrote:
> 
> >s x     = 3*x
> >s [x]   = 2*x
> >s [x,y] = x*y
> >
> >Start = s 4
> >
> >When compile it I get warning: "[test.icl,5,s] alternative will never 
> >match". Nevertheless program runs perfectly and gives expected result 
> >12.
>
> What's happening here is that apparently the compiler throws away the 
> second and
> third alternatives for s because the first alternative wil always 
> succeed. It does
> this before typechecking and therefore does not notice that the types 
> of these
> alternatives are inconsistent.

Presumably this behaviour is a (minor) bug in the Clean compiler...
it ought to do type checking before applying such optimizations, right?

-- 
Fergus Henderson <fjh@cs.mu.oz.au>  |  "I have always known that the pursuit
The University of Melbourne         |  of excellence is a lethal habit"
WWW: <http://www.cs.mu.oz.au/~fjh>  |     -- the last words of T. S. Garp.