I want to add 3 or more lists at once in one expression.
a ++ b ++ c
Will the ++ operator be evaluated from left to right or from right to left?
1. (a ++ b) ++ c 2. a ++ (b ++ c)
I would say option 2, because if ++ was a prefix function, we write ++ a ++ bc , which naturally leads to the evaluation of ++ bc in the first place. I am not sure that I am right.
But if this is option 1, it seems to me that a more effective change in the evaluation order from right to left is more efficient:
a ++ (b ++ c)
Here's why: a ++ b ++ c will first evaluate to ab ++ c by n steps (where n is the length of a, and ab is, of course, the concatenation of a and b), and then to abc at n + m more steps (m is the length of b, so n + m is the length of ab), which is only 2n + m steps. While a ++ (b ++ c) will be evaluated first to a ++ bc in m steps, and then to abc for more than n steps, which is the sum of only n + m steps.
I am new to haskell and not sure what I'm saying, I would like to receive confirmation.
source share