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

bind has different semantics than fmap #186

Closed
thurstonsand opened this issue Dec 23, 2016 · 3 comments
Closed

bind has different semantics than fmap #186

thurstonsand opened this issue Dec 23, 2016 · 3 comments

Comments

@thurstonsand
Copy link

thurstonsand commented Dec 23, 2016

I may not understand the underlying reasoning, but fmap takes parameters f mv whereas bind takes mv f, so if you wanted to thread these it would be difficult. Is there a reason why the order is different?

@yurrriq
Copy link
Collaborator

yurrriq commented Dec 24, 2016

As I understand it, cats is based (in part) on Haskell and its semantics. I've copied the relevant parts from GHC.Base here. N.B. >>= is pronounced bind.

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

class Applicative m => Monad m where
    -- | Sequentially compose two actions, passing any value produced
    -- by the first as an argument to the second.
    (>>=)       :: forall a b. m a -> (a -> m b) -> m b

The code above shows fmap takes a function from a to b and an a wrapped in a functorial context f then returns a b wrapped in the same functorial context f.

>>= or bind on the other hand, takes a monadic action m a and a function from a to a monadic action m b then returns a monadic action m b.

@thurstonsand
Copy link
Author

gotcha. makes sense to be consistent with haskell... still don't know the reasoning behind the different ordering tho

@ghost
Copy link

ghost commented Dec 30, 2016

still don't know the reasoning behind the different ordering tho

No reason other than the signatures of the Haskell methods. I agree that is a bit inconsistent.

@niwinz niwinz closed this as completed Apr 20, 2017
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

3 participants