I am very new to Haskell. Could someone please explain why defining a list like this returns an null list
ghci> let myList = [10..1]
ghci> myList
[]
However this works correctly.
ghci> let myList = [10, 9..1]
ghci> myList
[10, 9, 8, 7, 6, 5, 4, 3, 2, 1]
Basically, because
[10..1]is translated toenumFromTo 10 1which itself has the semantics to create a list by taking all elements less-than1which result from counting upward (with step-size+1) from (including)10.Whereas
[10, 9..1]is translated toenumFromToThen 10 9 1which explicitly states the counting step-size as9-10, i.e.-1(which is hard-coded to+1forenumFromTo)A more accurate specification can be found in the Haskell Report (6.3.4 The Enum Class):