Hi Gary,

We've had requests like this before
(Though I can't find it in http://haskell.systemsz.cs.yale.edu/hugs-bugs/)

If anyone feels like adding this, I'll be happy to add it in.
Here's how I think it can be done:

1) In an early phase of the compiler, add this line to the end
   of every case analysis/ pattern match:

   _ -> hugsError __FILE__ __LINE__

   where hugsError is a new builtin function and __FILE__ and __LINE__ are
   replaced by appropriate strings and ints.

2) After expanding each pattern match, try to eliminate redundant patterns.
   For example, print a warning if you find:

     case e of 
     [] -> e1
     [] -> e2

   or

     case e of 
     [] -> e1
     (:) x xs -> e2
     _ -> e3

   Suppress the warning if e3 is a call to hugsError

   Remember to watch for these special cases:

     case e of
     x | True -> e1            -- always executes
     x | otherwise -> e2       -- always executes
     ...


3) Print a warning message if and calls to hugsError remain at the end.

> This isn't a bug in Hugs; it's a request for an enhancement.
> 
> It would be very nice if hugs would statically check the definitions
> in a module to see if all patterns for a type are covered.  For example, if
> the user wrote a function 
> 
> > sum_all :: [Int] -> Int
> > sum_all (x:xs) = x + sum_all xs
> 
> then hugs should warn the user that the pattern [] is not covered
> by the definition.  This warning might be toggled by a command line
> switch if annoying.
> 
> SML has this feature, at least in the implementations I've used (SML/NJ),
> and it's very helpful for students.
> 
>         Gary Leavens
>         229 Atanasoff Hall, Department of Computer Science
>         Iowa State Univ., Ames, Iowa 50011-1040 USA
>         [EMAIL PROTECTED]  phone: +1 515 294-1580 fax: +1 515 294-0258
>         URL: http://www.cs.iastate.edu/~leavens/homepage.html
> 


Reply via email to