|At the last minute, I have found some Enum bugs in 1.2.beta.
|As I don't know if they have been fixed in 1.2.gamma, which
|I guess was circulated yesterday, here they are:

Thanks, Mikael.

|   1) According to the specification (section 3.9), the
|      value of
|
|               [ 7, 7 .. 3 ]
|
|      is the infinite list [ 7, 7, 7, 7,...], but the
|      default definition of enumFromThenTo (pp. 30 and 91)
|      gives the value
|
|               takeWhile (<= 3) enumFromThen 7 7
|
|      which is the empty list!

I think it's section 3.9 that's wrong here.  Can we please change the
two occurences of "the increment is positive" to "the increment is
nonnegative" and then clarify which cases lead to an infinite list?


|   2) Similarly, the value of
|
|               ['z', 'y' .. 'a']
|
|      should be the alphabete in reverse order, but according to
|      the Enum instance of Char (p. 92), we get
|
|         takeWhile (>= 'a') (map chr [ord 'z', ord 'y' .. ord maxChar]) ==
|         takeWhile (>= 'a') (map chr []) ==
|         [],
|
|      i.e, also the empty list.
|
|   Suggested fixes:
|
|   1) The default definition of enumFromThenTo (pp. 30 and 91)
|     should be:
|
|     enumFromThenTo n n' m | n < n'  = takeWhile (<= m) (enumFromThen n n')
|                          | n > n'  = takeWhile (>= m) (enumFromThen n n')
|                          | n == n' = repeat n
|                          | otherwise = error "enumFromThenTo{PreludeCore}: \
|                                              \no ordering relation"

See above.  I don't think this is what we really want.  The sequence
should always terminate when the increment is nonnegative and the value
exceeds the limit or the increment is negative and the value is less
than the limit.  (This is a shortcoming of this notation; there is
a real virtue in having to say "upTo" or "downTo" or some such.)
(Note: The otherwise case isn't really necessary.  Incrementing or
decrementing on a partial order aren't well-defined anyway.)

|   2) The instance Enum Char (p. 92) should read:
|
|     enumFromThen c c' | c < c'  = map chr [ord c, ord c' .. ord maxChar]
|                      | c > c'  = map chr [ord c, ord c' .. ord minChar]
|                      | otherwise = repeat c

I think this should then be

    enumFromThen c c' = map chr [ord c, ord c' ..
                                    ord (if c' < c then minChar else maxChar)]

--Joe

Reply via email to