From Learn You a Haskell:
Think about this list:
[5]
. That’s just syntactic sugar for5:[]
. On the left side of the:
, there’s a value; on the right side, there’s a list. In this case, it’s an empty list. Now how about the list[4,5]
? Well, that desugars to4:(5:[])
. Looking at the first :, we see that it also has an element on its left side and a list,(5:[])
, on its right side. The same goes for a list like3:(4:(5:6:[]))
, which could be written either like that or like3:4:5:6:[]
(because:
is right-associative) or[3,4,5,6]
.
For the bolded part, I was expecting the growing list to culminate in 3:(4:(5:(6:[])))
. This has something to do with my lack of understanding of currying, associativity, or both. Can someone tell me the flaw in my thinking?