STR-732: fold transposes arguments of binary operator
the code for foldl:
FoldL(s) : ([x | xs], y) -> (xs, (x, y))
foldl(s) =
rec x( ([], y) -> y + FoldL(s); x)tranposes the arguments in the call:
(x,y) in the auxiliary rule Foldl.
This puts the latest list element x on the LHS
and the accumulator on the RHS of the operatorThe problem is manifest in calls like:
<foldl(conc)> ([[1],[2],[3]],[])
which yields [3,2,1]
and
foldl(subtr) ([1,2,3],0)
which gives 2 rather than -6
One possible fix is the redefinition:
FoldL(s) : ([x | xs], y) -> (xs, (y, x))
Submitted on 10 January 2008 at 02:44
Log in to post comments