-
Notifications
You must be signed in to change notification settings - Fork 43
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
put function argument last in higher order functions #31
Comments
I would prefer not to change the parameter order now. |
In Haskell, it makes sense as it's common to curry the fmap call with its function argument. See the strings package, for example - all the functions that take function arguments I don't think this is particularly specific to fmap - it applies to any function that |
Good points. I'll really think about it. |
So here is an example that shows that its not always possible to distinguish which parameter we are mapping over which. I am getting this example from monadic error handling. I just decided not to implement compose using fmap and join, but it does not mean that its not currently possible. func deriveFmap(f func(b) (c, error), g func(a) (b, error)) func(a) (func() (c, error), error) If types a, b and c are the same then we have: func deriveFmap(f func(a) (a, error), g func(a) (a, error)) func(a) (func() (a, error), error) Then its impossible to tell whether we are mapping I am not saying no. I am just saying we need to be careful. |
When writing deriveFmap or deriveFilter, it's often nice to write
the predicate function inline. Since that can often take
multiple arguments, the code reads more nicely when
the function comes second and the slice comes first,
so it's clear at first glace what slice is being operated on
before starting to read the function itself.
For example:
rather than:
Alternatively, the goderive code could allow both forms and generate the
expected function signature based on the argument types that are passed
in.
The text was updated successfully, but these errors were encountered: