I came across an exercise in one of my lectures that left me confused on the output of [2, 2 .. 2]. Why when entering [2, 2 .. 2] it generates an "infinite" list with 2's.
The way i understood the notation was that the first element is the start bound, the second the "gap" between the numbers, and the last is the end of the list, in other words stop when reaching that number.
If my reasoning is right, why does the expression [2, 2 .. 2] not output [2]?.
I thought Haskell might evaluate it this way;
- When printing the first element of the list it is equal to the last, therefore stop.
- Or, if the first element is not checked against the "outer" bound, then the output would be [2, 2] because when adding zero to the previous number (in out case the start-bound 2) we would have reached the end and therefore stop.
I obviously do not understand the workings of the notation correctly, so how does Haskell evaluates the expression?