Decrementing ranges in Haskell

Viewed 9900

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]
4 Answers

For newbies.

To make a list with all the numbers from 20 to 1, you can't just do

[20..1]

you have to specify as such:

[20,19..1]
Related