Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How are strings compared in haskell?

I just started studying Haskell and I'm reading a book called: Learn You a Haskell for Great Good!

In chapter 2, there is something I don't get.

When I am comparing two strings using the ">" operator for ex:

ghci> "Abrakadabra" < "Zebra"

True

I don't understand why it returns true. I tried to analyze this based on characters being ASCII, but I still don't understand why. What I thought is that we compare the number of characters in the string, but this example changed how I understood it in the first place.

Could someone please clarify this for me?

like image 347
Ralph Avatar asked Jul 09 '26 17:07

Ralph


1 Answers

This is lexicographic ordering, which is what you should expect if you look something up in a dictionary.

like image 86
Thomas M. DuBuisson Avatar answered Jul 14 '26 06:07

Thomas M. DuBuisson



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!