[m-users.] [Beginner] Fixing a type error in parameter of foldl

Zoltan Somogyi zoltan.somogyi at runbox.com
Sat Oct 15 20:39:10 AEDT 2022



On Sat, 15 Oct 2022 15:03:12 +0530, Razetime <rraghu.11502 at gmail.com> wrote:

> Thanks for the help. I got a new error on this code but I managed to
> figure it out. It is very confusing that the initial value argument of
> list.foldl is not passed in as the first argument of the predicate,
> but as the second argument.

That depends on your expectations. People with a functional programming
background would expect the predicate to be first, because it makes
far more sense to curry *that* argument, than the initial accumulator value.
If two groups of people have opposite expectations, there is no way you
can please both of them at the same time.

Note that the initial and final value of the accumulator
must be next to each other if you want to enable the use
of state variable notation for them, which we do.

> The expected type in this case shows which
> arguments must have the same type, correct?

Correct.

Zoltan.


More information about the users mailing list