can anyone tell how the output of this function would be true in haskell.

however haskell calculates it first element, second element and so on..

so in first step : 3>2 : True

in Second Step : 2>10 : False

how the final output would be True?

I don't know how Haskell implements this check, but for your lists [3,2,1] and [2,10,100] the comparison might be something like:

Is 3 = 2? No, so check if 3 > 2: ==> true and we're done.

If your lists were [3,2,1] and [

**3**,10,100], then the comparison might be:

Is 3 = 3? Yes, so check next element instead:

Is 2 = 10? No, so check if 2 > 10: ==> false

The real implementation may do the = and > checks in a different order and it will also handle empty lists, but the basic principle is clear.

No more Blub for me, thank you, Vicar.

chris webster wrote:The comparison checks each pair of values in turn and it can stop when an element in one list is not equal to its counterpart in the other list, because now it can answer the question "is X > Y?". It's like an alphabetical comparison e.g. "BBC" > "ACD".

I don't know how Haskell implements this check, but for your lists [3,2,1] and [2,10,100] the comparison might be something like:

Is 3 = 2? No, so check if 3 > 2: ==> true and we're done.

If your lists were [3,2,1] and [3,10,100], then the comparison might be:

Is 3 = 3? Yes, so check next element instead:

Is 2 = 10? No, so check if 2 > 10: ==> false

The real implementation may do the = and > checks in a different order and it will also handle empty lists, but the basic principle is clear.

looks like in each (ie. <, >), it first checks for =.

but what is the use for that, however i want to check for >.

**is not >**element Y, then you still need to know if X = Y, in which case you need to check the next pair of elements, or if X < Y, in which case you know that list X

**is not >**list Y.

So let's try it your way with lists [3, 2, 1] and [2, 10, 100]:

Is [3, 2, 1] > [2, 10, 100]?

Is 3 > 2? Yes, so return

**true**and stop. List [3, 2, 1]

**is >**list [2, 10, 100].

But if you try it with lists [3, 2, 1] and [

**3**, 10, 100]:

Is 3 > 3? No, so check: is 3 = 3?

Yes, 3 = 3, so now we have to check the next element in the lists to see which is greater.

Is 2 > 10? No, so check: is 2 = 10? No, so 2 must be < 10, which means we can return

**false**and stop, because list [3, 2, 1]

**is not >**list [3, 10, 100].

Haskell compares each pair of elements in the lists in turn, and stops as soon as it can answer the question you asked i.e. is list X > list Y? Or when it reaches the end of one of the lists.

It's really not that hard. Think about how you compare two strings (lists of characters) alphabetically - it's the same principle. In fact, Learn You A Haskell tells you this:

Learn You A Haskell wrote:When using <, <=, > and >= to compare lists, they are compared in lexicographical order. First the heads are compared. If they are equal then the second elements are compared, etc.

No more Blub for me, thank you, Vicar.