Report Issues

Janis Voigtlaender voigt@orchid.inf.tu-dresden.de
Fri, 04 Jan 2002 12:06:56 +0100


Simon Peyton-Jones wrote:
> 
> Folks,
> 
> You have all been eating too much Xmas pudding.   Only one
> Haskell98 Report issue has arisen since my release of 21 Dec.

OK, here comes a rather trivial issue regarding the libraries:

Section 7.6 of the Library Report gives the following example definition
of nub:

nub                     :: (Eq a) => [a] -> [a]
nub []                  =  []
nub (x:xs)              =  x : nub (filter (\y -> x /= y) xs)

But then, in Section 7.9, the following actual implementation is given:

nub                     :: Eq a => [a] -> [a]
nub                     =  nubBy (==)

nubBy                   :: (a -> a -> Bool) -> [a] -> [a]
nubBy eq []             =  []
nubBy eq (x:xs)         =  x : nubBy eq (filter (\y -> not (eq x y)) xs)

The two definitions are only equivalent, if for all x and y holds that 
     (x /= y)
and
     (not (x == y))
are equivalent.
While this is true for all basic types, and is also true for user
defined instances of Eq, if the programmer specifies only one of the two
functions (==) or (/=) and leaves the other one at the default method,
nobody can prevent me from writing an instance declaration where I
define (==) and (/=) without adhering to the duality. This might be
stupid to do, but still it contradicts the report, right?

Janis.


--
Janis Voigtlaender
http://wwwtcs.inf.tu-dresden.de/~voigt/
mailto:voigt@tcs.inf.tu-dresden.de