Re: [elm-discuss] Order of arguments in mapping function in foldl/foldp

65 views
Skip to first unread message

Evan Czaplicki

unread,
Jun 27, 2015, 12:15:44 PM6/27/15
to elm-d...@googlegroups.com
Yep! http://package.elm-lang.org/help/design-guidelines#the-data-structure-is-always-the-last-argument

From working with SML, OCaml, and Haskell, I always found the SML way the best. Changing the order of traversal does not change anything else about your code. Furthermore, you don't have to go look at the docs every single time to remember which is which (a thing I still do sometimes in Haskell: "which way does foldM go?")

On Sat, Jun 27, 2015 at 8:09 AM, Robert Looby <robert...@gmail.com> wrote:
The function passed to List.foldl/List.foldp has the current value first and the accumulated value second. Ex)

List.foldl (\element memo -> memo ++ element) "a" ["b", "c", "d"] -- "abcd"

This is backwards from similar functions in most other languages:

Is there a reason it was done this way?

--
You received this message because you are subscribed to the Google Groups "Elm Discuss" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elm-discuss...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply all
Reply to author
Forward
0 new messages