I am tryng to learn Haskell and have begun reading a book on it. It seems pretty interesting and want to continue my journey even if it's hard to grasp at first. I have this piece of code and I want to understand why it works.
names = [("Ian", "Curtis"), ("Bernard", "Summer"), ("Peter", "Hook"), ("Stephen", "Morris")]
compareLastNames name1 name2
| lastName1 > lastName2 = GT
| lastName1 < lastName2 = LT
| otherwise = EQ
where
lastName1 = snd name1
lastName2 = snd name2
main = do
print (sortBy compareLastNames names)
What I don't understand is compareLastNames takes two arguments but even if I pass it a list of tuples, it just works. I know haskell curries functions but how does it work. How is it possible for the function to accept a list of tuples and not throw an error?