So I’m reading http://learnyouahaskell.com/starting-out as it explains lists, and using ghci on Vista 64. It says that [2,4..20] steps by 2 from 4 to 20. This works. It says [20,19..1] goes from 20 to 1, but doesn’t explain. I take it that the first number is NOT the step, the step is the difference between the 1st and 2nd number. This is confirmed by [4,4..20] which hangs (no error message, must kill console). This is unlike operators like !! and take which check the index’s range and give an error message.
My question is: is this a bug on Vista port or is that the way it’s supposed to be?
[x,y..z]does indeed step from x to z by stepy-x. Wheny-xis 0 this leads to an infinite list. This is intended behavior.Note that if you use the list in an expression like
take 20 [2,2..20], ghci won’t try to print the whole list (which is impossible with infinite lists of course) and it won’t “hang”.