I have tried to compare elements belonging to two lists in Haskell and I do not understand the result obtained.
Cito de aprendehaskell.es :
Lists can be compared if the items they contain can be compared. When we use & lt ;, < =, & gt ;, and > = to compare lists, they are compared in lexicographical order. First the heads are compared. Then the second elements are compared and so on.
I decided to try the following comparison in the WinGHCI compiler:
Prelude> [1,2,3] < [4,5,2]
The result obtained was: True
What I understood from the quote, is that when comparing in lexicographical order, first compare 1 with 4, and as 1 < 4, it is true, then compare 2 with 5, and as 2 < 5 true, but when comparing 3 < 2, false
should come out. So the result that I expected was false. However, I get true.
The question is, Haskell only compares the first element and does not compare the rest, or does he compare the first first, then the second ...? BUT do you always keep the result of the first one? which would be absurd, since it would not make sense to carry out the rest of operations since the result will not vary.
Thanks