News for hackers. Stuff that matters.
Re:Idiomatic Monads in Rust by mesarvagya on Thursday April 04, 2019 @09:41AM (#19572143)
I am not sure about whether the functor definition in article is correct or not.

Isn't it supposed to lift function as below:

class Functor f where map :: (a -> b) -> f a -> f b

instead of: class Functor f where map :: f a -> (a -> b) -> f b

Re:Idiomatic Monads in Rust by kccqzy on Thursday April 04, 2019 @12:53PM (#19574469)
They are the same. I believe it's deliberately written this way to make the comparison with monad more obvious.

    map  :: Functor     m => m a ->   (a ->   b) -> m b
    ap   :: Applicative m => m a -> m (a ->   b) -> m b
    bind :: Monad       m => m a ->   (a -> m b) -> m b
Re:Idiomatic Monads in Rust by ivanbakel on Thursday April 04, 2019 @09:44AM (#19572175)
The definitions are identical. You could define one in terms of the other by just reversing the arguments.
Re:Idiomatic Monads in Rust by mesarvagya on Thursday April 04, 2019 @09:50AM (#19572237)
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.
Re:Idiomatic Monads in Rust by masklinn on Thursday April 04, 2019 @11:26AM (#19573418)
> 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
    });
Re:Idiomatic Monads in Rust by ivanbakel on Thursday April 04, 2019 @10:05AM (#19572407)
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
Re:Idiomatic Monads in Rust by majewsky on Thursday April 04, 2019 @12:17PM (#19574065)
Or, more succinctly,

  map' = flip map''
  map'' = flip map'
Re:Idiomatic Monads in Rust by feanaro on Thursday April 04, 2019 @10:22AM (#19572611)
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).