Definition of foldl possibly incorrect in SML / NJ 110.75

Signature foldl in SML / NJ 110.75

foldl;
val it = fn : ('a * 'b -> 'b) -> 'b -> 'a list -> 'b

Also, if I give:

foldl (op -) 2 [1];

I will take ~ 1 instead of 1 as an answer

Can you confirm my conclusions?

0
source share
1 answer

From the database: http://www.standardml.org/Basis/list.html#SIG:LIST.foldl:VAL

foldl f init [x1, x2, ..., xn] returns

f(xn,...,f(x2, f(x1, init))...)

or init if the list is empty.

Thus, the foldl (op -) 2 [1]result is an assessment xn - initor1 - 2

What makes this specific example a little harder to understand is that it (op -)is a non-associative infix operator. Thus, fin the definition of the base library, it moves between xnand init.

, , 'a 'b .

+2

All Articles