Skip to content
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

liftM2 documentation seems not coherent with its implementation #97

Closed
ilario-pierbattista opened this issue Jul 25, 2019 · 3 comments
Closed

Comments

@ilario-pierbattista
Copy link
Contributor

Hi,

I was looking to the documentation of liftM2:

* liftM2 :: Monad m => (a -> b -> c) -> m a -> m b -> m c

which is similar to the haskell version.

However the implementation seems to be wrong: $transformation is not used as a pure function.

function liftM2(
callable $transformation = null,
Monad $ma = null,
Monad $mb = null
) {
return curryN(
3,
function (
callable $transformation,
Monad $ma,
Monad $mb
) {
return $ma->bind(function ($a) use ($mb, $transformation) {
return $mb->bind(function ($b) use ($a, $transformation) {
return $transformation($a, $b);
});
});
}
)(...func_get_args());
}

It seems to be like bind2.
Am I missing something?

Thanks

@ilario-pierbattista ilario-pierbattista changed the title liftM2 documentation seems not coherent with its implementation liftM2 documentation seems not coherent with its implementation Jul 25, 2019
@widmogrod
Copy link
Owner

@ilario-pierbattista grate finding! You're correct.

To make implementation valid. This change is required:

-return $transformation($a, $b); 
+return $ma::of($transformation($a, $b));

@ilario-pierbattista
Copy link
Contributor Author

Why not just changing the latest bind to a map?

@widmogrod
Copy link
Owner

There are many roads to Rome. No particular reason.

ilario-pierbattista added a commit to ilario-pierbattista/php-functional that referenced this issue Jul 29, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants