Hacker News new | past | comments | ask | show | jobs | submit login

The definitions are identical. You could define one in terms of the other by just reversing the arguments.



The first definition is says it takes a normal function and returns a function in category f. But second definition says it takes a value fa and a function and return fb. Does the order of defining arguments matters or its just a taste of matter? Thanks.


> Does the order of defining arguments matters or its just a taste of matter?

It's only a matter of taste or convenience. Haskell is a curried language, so you put the callback first to help partial application, and reversing the order is just a `flip` away.

Rust is uncurried and uses a C-style syntax, so you generally put lambdas in tail position, for a more block-y usage:

    foo.bar(x, |y| {
        // body
    });


Don't make the mistake of thinking that translating a type signature into written English gives a canonical description of the function. The first definition says "(a -> b) -> f a -> f b" - that is it.

You can translate one into the other easily

    map' :: (a -> b) -> f a -> f b
    map' i j = map'' j i

    map'' :: f a -> (a -> b) -> f b
    map'' m n = map' n m


Or, more succinctly,

  map' = flip map''
  map'' = flip map'


You're thinking in terms of currying, which Rust doesn't support. If you could partially apply arguments to functions in Rust, your reasoning would be correct, though the functions would still be equivalent since you can define `flip` (as in Haskell).




Join us for AI Startup School this June 16-17 in San Francisco!

Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: