I’m learning f# from msdn and looking and trying out the reduce and reduce back, I can’t find any difference, the signature is the same
('T -> 'T -> 'T) -> 'T list -> 'T
and they both throw same error on empty list, so why is there 2 of them, there should be some difference
Others already explained the difference – they reduce elements in a different order.
For most of the operations that you can use with
reduceorreduceBack, the difference does not actually matter. In more mathematical terms, if your operation is associative (such as numeric operations, max, min or sum functions, list concatenation, etc.) then the two behave the same.An example where you can nicely see the difference is building a tree, because that exactly shows how the evaluation works:
Here are the two trees that you get as the result (but note that if you flatten them, then you get the same list!)