There appears to be an error in the List library module definition of
Haskell 1.3. It definitely occurs in the Hugs distribution but as that
module appears to be the same as the standard Haskell 1.3 version it
is likely that it occurs in any Haskell system that uses the List library
module. I apologise in advance if this has already been widely reported but
I could not see any reference to this in the WWW version of the Errata for the
Haskell 1.3 report.

The error can be seen from in list difference function.
Although [1,2,3,4] \\ [1] gives the correct result
        List> [1,2,3,4] \\ [1]
        [2, 3, 4]
the following does not
        List> [1,2,3,4] \\ [3]
        [4]

The problem is in the definition of deleteBy
        deleteBy                :: (a -> a -> Bool) -> a -> [a] -> [a]
        deleteBy eq x []        = []
        deleteBy eq x (y:ys)    = if x `eq` y then ys else deleteBy eq x ys
which doesn't keep y in the else case. The following definition fixes the
problem:
        deleteBy                :: (a -> a -> Bool) -> a -> [a] -> [a]
        deleteBy eq x []        = []
        deleteBy eq x (y:ys)    = if x `eq` y then ys else y:(deleteBy eq x ys)

Cheers, Bruce




-- 
Dr. Bruce McKenzie, Head of Department, Department of Computer Science,
University of Canterbury, Private Bag 4800, Christchurch,   New Zealand
Internet: [EMAIL PROTECTED]        Phone: +64 3 364 2349
WWW page: http://www.cosc.canterbury.ac.nz/~bruce   FAX: +64 3 364 2569      



Reply via email to