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

Suggestion: map2 variant that builds the cartesian product #547

Closed
srijs opened this Issue Apr 2, 2016 · 1 comment

Comments

Projects
None yet
2 participants
@srijs

srijs commented Apr 2, 2016

Hi!

As someone coming to Elm from Haskell, I was quite surprised by the fact that map2 doesn't work coherently with concatMap.

I would have expected this to hold:

List.map2 f xs ys = List.concatMap (\a -> List.map (f a) ys) xs

In other words, map2 building the cartesian product of both lists, instead of zipping. The reason I expected it is because I was looking at map2 and concatMap as the Elm variants of <*> and >>=.

I actually think that a zipping map2 is more approachable, so I like the way things currently are. However, I was wondering whether you would be open to adding the other functionality as well, under a different name (and possible extend the docs to make that clearer)?

@jvoigtlaender

This comment has been minimized.

Show comment
Hide comment
@jvoigtlaender

jvoigtlaender Apr 2, 2016

Contributor

First, please read https://github.com/elm-lang/core/blob/master/CONTRIBUTING.md#adding-new-functions.

So, such a function, if considered for addition, should first go into some *-extra package. And indeed, it already is: http://package.elm-lang.org/packages/circuithub/elm-list-extra/3.10.0/List-Extra#lift2.

About documentation: Maybe the current documentation for the List module in the core package should prepare against the surprise you encountered? You could make a suggestion for how to change the current documentation as shown at http://package.elm-lang.org/packages/elm-lang/core/3.0.0/List#map2. For that, please open a new issue or pull request.

Contributor

jvoigtlaender commented Apr 2, 2016

First, please read https://github.com/elm-lang/core/blob/master/CONTRIBUTING.md#adding-new-functions.

So, such a function, if considered for addition, should first go into some *-extra package. And indeed, it already is: http://package.elm-lang.org/packages/circuithub/elm-list-extra/3.10.0/List-Extra#lift2.

About documentation: Maybe the current documentation for the List module in the core package should prepare against the surprise you encountered? You could make a suggestion for how to change the current documentation as shown at http://package.elm-lang.org/packages/elm-lang/core/3.0.0/List#map2. For that, please open a new issue or pull request.

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