New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Flipping arguments in foldl's step function #340

Closed
sindikat opened this Issue Aug 10, 2015 · 2 comments

Comments

Projects
None yet
2 participants
@sindikat

sindikat commented Aug 10, 2015

Elm's foldr has the same type as Haskell's foldr:

foldr : (a -> b -> b) -> b -> List a -> b -- Elm
foldr :: (a -> b -> b) -> b -> t a -> b  -- Haskell

However Elm's foldl has a different type, than Haskell's foldl:

foldl : (a -> b -> b) -> b -> List a -> b -- Elm
foldl :: (b -> a -> b) -> b -> t a -> b  -- Haskell

Changing type of foldl in Elm is API-breaking, but it makes sense. When you fold a list from left, your step function looks like (\acc e -> ...) — the accumulator is to the left of the current element, because the accumulator is to the left of the list itself. This is a good visual intuition. Also there is no reason to arbitrarily deviate from Haskell, if it doesn't benefit Elm (or there are benefits that I don't know about?).

Can we consider that? If no, can we maybe add the note to documentation to avoid confusion?

@evancz

This comment has been minimized.

Show comment
Hide comment
@evancz

evancz Aug 11, 2015

Member

The reasoning is here and matches how things work in Standard ML which I find the clearest and nicest of the ML family languages.

I get why Haskell did it that way, but in practice I find it super annoying. I also am not targeting Haskell programmers primarily. I trust that they'll be able to sort out any minor differences (like colon vs double colon) and I can do what's right for the broader Elm community which will primarily be made up of folks coming from JS and ruby and python and such.

There are probably discussions on elm-discuss going into more detail about why things are this way, so def check that out for more information!

Member

evancz commented Aug 11, 2015

The reasoning is here and matches how things work in Standard ML which I find the clearest and nicest of the ML family languages.

I get why Haskell did it that way, but in practice I find it super annoying. I also am not targeting Haskell programmers primarily. I trust that they'll be able to sort out any minor differences (like colon vs double colon) and I can do what's right for the broader Elm community which will primarily be made up of folks coming from JS and ruby and python and such.

There are probably discussions on elm-discuss going into more detail about why things are this way, so def check that out for more information!

@evancz evancz closed this Aug 11, 2015

@sindikat

This comment has been minimized.

Show comment
Hide comment
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment