Suppose we have a list
x = [1..10]
and we intend to create another list y using this in this manner :
y= [a|a<-x]
So while creating the list y
from x
, it accesses each element of x
( from 1 to 10) and inserts it in y
in the same order. As a list in haskell is singly linked list, we can insert a new element only at its head. So first it inserts 1 to []
& we have [1]
. Then it inserts 2 to its head & so we have [2,1]
. Then it inserts 3 & we have [3,2,1]
& so on. So ultimately we should get y
as [10,9..1]
. But instead we get y
as [1..10]
. Why is that so?