Hi!

I'm slightly puzzled about the definition of list enumerations in
GHC (and possibly other Haskell implementations)...

Example:

``[0, 2 .. 9] :: [Int]''
        ==> [0, 2, 4, 6, 8]

Quite what one expects, right?

Now consider the case for Floats and friends:

``[0.0, 2 .. 9] :: [Float]''
        ==> [0.0, 2.0, 4.0, 6.0, 8.0, 10.0]

*eh?* The latter list comprehension is IIRC translated into
 ``numericEnumFromThenTo 0.0 2.0 9.0'', which in turn is (in current
 GHC's) defined as:

\begin{code} 
numericEnumFromThenTo   :: (Ord a, Fractional a) => a -> a -> a -> [a]
numericEnumFromThenTo e1 e2 e3 = 
    takeWhile pred (numericEnumFromThen e1 e2)
  where
    mid = (e2 - e1) / 2
    pred | e2 > e1   = (<= e3 + mid)
         | otherwise = (>= e3 + mid)
\end{code}
 

IMHO, it's a bit counterintuitive, isn't it? To me, e3 is considered
as upper bound and NONE of the elements of the resulting list should
be GREATER than this bound (except for rounding errors, which might
not be so easy to catch).

Nevertheless, this behaviour is defined by the Haskell98 standard!
(See ~ #3.10)

Can somebody please point me to the rationale behind the design
decision? Undoubtedly there is one, but I don't seem to be able to
find it... ?:-}


Cheers,
Michael
p.s.: feel free to redirect this message to a more appropriate list,
      but then please keep me in the CC field. Thanks!
-- 
 /~\ ASCII ribbon | Compaq Safety & Comfort Guide:
 \ / campaign     | "Stand up and take a few minutes to stretch and
  X  against      |  exercise several times a day."
 / \ HTML mail    |

Reply via email to