Thanks @HaraldGliebe & @LuisMiguelMejíaSuárez for your great responses. I am enlightened now!. I am just summarisig the answer here which may benefit others who read this thread.
"/:" is actually the name of the function which is defined inside the List class. The signature of the function is: /:[B](z: B)(op: (B, A) ⇒ B): B --> where B is the type parameter, z is the first parameter; op is the second parameter which is of functional type.
The function follows curried version --> which means we can pass less number of parameters than that of the actual number. If we do that,
the partially applied function is stored in a temporary variable; we can then use the temporary variable to pass the remaining parameters.
If supplied with all parameters, "/:" can be called as: x./:(0)(_+_) where x is val/var of List type. OR "/:" can be called in two steps which are given as:
step:1 val temp = x./:(0)(_) where we pass only the first parameter. This results in a partially applied function which is stored in the temp variable.
step:2 temp(_+_) here using the partially applied function temp is passed with the second (final) parameter.
If we decide to follow the first style ( x./:(0)(_+_) ), calling the first parameter can be written in operator notion which is: x /: 0
Since the method name ends with a colon, the object will be pulled from right side. So x /: 0 is invalid and it has to be written as 0 /: x which is correct.
This one is equivalent to the temp variable. On following 0 /: x, second parameter also needs to be passed. So the whole construct becomes: (0/:x)(_+_)
This is how the definition of the function sum in the question, is interpreted.
We have to note that when we use curried version of the function in operator notion, we have to supply all the parameters in a single go.
That is: (0 /: x) (_) OR (0 /: x) _ seems throwing syntax errors.
/:is a (now deprecated) alias tofoldLeftthe same applies to:/withfoldRiight. If you look at the scaladoc you will see that both methods receive two parameters lists. One for the zero element of the folding. And the other for the aggregation function. - Luis Miguel Mejía Suárezxs./:(0)(_ + _). Is a method with two parameters lists. Thus passing just one parameter is not really returning anything. Second because of many syntactic rules it can be called without the dot and passing first the zero element and then the collection and finally the function. But, as I said, the alias is deprecated, al most no body used it (except for haskallators), it caused confusions and it is hard to get the precedence right. I would not really care about it and just use foldLeft / foldRight instead. - Luis Miguel Mejía Suárez