The syntax [e1, e2 .. e3] is really syntactic sugar for enumFromThenTo e1 e2 e3, which is a function in the Enum typeclass.
The Haskell standard defines its semantics as follows:
For the types
IntandInteger, the enumeration functions have the
following meaning:
- The sequence
enumFrom e1is the list[e1,e1 + 1,e1 + 2,…].- The sequence
enumFromThen e1 e2is the list[e1,e1 + i,e1 + 2i,…],
where the increment,i, ise2 − e1. The increment may be zero or
negative. If the increment is zero, all the list elements are the
same.- The sequence
enumFromTo e1 e3is the list[e1,e1 + 1,e1 + 2,…e3].
The list is empty ife1 > e3.- The sequence
enumFromThenTo e1 e2 e3is the list[e1,e1 + i,e1 +, where the increment,
2i,…e3]i, ise2 − e1. If the increment is
positive or zero, the list terminates when the next element would be
greater thane3; the list is empty ife1 > e3. If the increment is
negative, the list terminates when the next element would be less than
e3; the list is empty ife1 < e3.
This is pretty much what you’d expect, but the Float and Double instances are defined differently:
For
FloatandDouble, the semantics of theenumFromfamily is given by the rules forIntabove, except that the list terminates when the elements become greater thane3 + i∕2for positive incrementi, or when they become less thane3 + i∕2for negativei.
I’m not really sure what the justification for this is, so the only answer I can give you is that it is that way because it’s defined that way in the standard.
You can work around this by enumerating using integers and converting to Float afterward.
Prelude> map fromIntegral [1, 3 .. 10] :: [Float]
[1.0,3.0,5.0,7.0,9.0]