News for hackers. Stuff that matters.
Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by dragonwriter on Monday January 05, 2015 @09:39AM (#8838958)
None of those names "mean nothing"; they all have very specific meanings. Its true that in the case of return, the meaning in the context of Haskell monads is somewhat special, but since its part of the actual syntax of Haskell do-notation, its particularly important to address it in Haskell-oriented monad tutorials, whether or not it was the best choice from a syntax design perspective.
Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by chriswarbo on Monday January 05, 2015 @11:02AM (#8839424)
You may already be aware of this, but for those who aren't: `return` isn't actually part of do-notation syntax, it's a function name. It's true that do-notation must result in a monadic value, but that's just because of the type. `return` can be used to construct that monadic value, but there are many other ways to do so:

    func1 :: Maybe Int
    func1 = do x <- foo
               y <- bar
               return (x + y)  -- Using return

    func2 :: Maybe Int
    func2 = do x <- foo
               y <- bar
               Just (x + y)  -- Building a monadic value explicitly

    func3 :: Maybe Int
    func3 = do x <- foo
               y <- bar
               plusJust x y  -- Using some other function

    plusJust :: Int -> Int -> Maybe Int
    plusJust x y = Just (x + y)
Also, since `return` is a function, we can use it outside do-notation:

    wrapAndApply :: a -> (a -> b) -> [b]
    wrapAndApply x f = fmap f (return x)
What makes `return` "special" is that it's a method of the `Monad` typeclass. In other words, the name `return` is overloaded to work with any instance of `Monad` (`IO`, `Maybe`, `List`, etc.), depending on the type that's required of it.

Loads of other functions are overloaded like this, eg. `+` has implementations for `Int`, `Float`, etc. so it's not monad-specific.

The part which is monad-specific is that Haskell's do-notation is hard-coded to the built-in Monad typeclass. We're completely free to make our own monad implementation, separate to Haskell's built-in one, but we won't be able to use do-notation with them unless we implement the built-in `Monad` typeclass as well. That could be as simple as mapping one name to the other:

    instance MyMonad a => Monad a
        return = myReturn
        (>>=)  = myBind
Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by dllthomas on Monday January 05, 2015 @01:28PM (#8840244)
"The part which is monad-specific is that Haskell's do-notation is hard-coded to the built-in Monad typeclass."

That's not quite true, at least in GHC. It's hard-coded to use (>>=) and fail, but the only thing that prevents you from defining your own is the name collision. With -XNoImplicitPrelude, you can (and they can even be locally scoped - I did some cute things with this once that I'd never want to see in production code...).

Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by klibertp on Monday January 05, 2015 @02:03PM (#8840470)
No. You desperately insist on giving them meaning. And sometimes, which is worse, the meaning you want to give them is completely unrelated or even opposed to everything they are or do.

Aside: You realize that the word "monad" (and "dyad") already has a very specific meaning and that you assaulted that meaning and now are trying to beat the poor word into submission? If I had to choose I'd say that J programmers have much more of a right to use and define this word: a single-argument function ("mono") makes more sense to be called a "monad" than an instance of "flat-mappable" interface.

> since its part of the actual syntax of Haskell do-notation

It's not, which makes using it even dumber - as it's no problem at all to change it.

F# uses monads extensively, as one of the selling points of the language, yet the m-word rarely if ever is mentioned in the docs. That's because designers of that language were rational enough to realize that "computation expression" is a name that both conveys some basic intuition about the thing in question and is concise enough to allow talking about the thing abstractly. From my perspective I don't see any, at all, arguments for persistent use of the M-word by the community of some programming language. Other than trying to be different, or something.

Believe it or not, names do matter. Good name speeds up learning/understanding considerably; a bad name slows it down. It's sometimes - rarely! - worth it to invent completely new name. That's when the thing you want to name really is dissimilar to anything else and when re-using some name would introduce false intuitions about the object. But monads ARE NOT SUCH THINGS (sorry for shouting). "You could have invented monads", and quite possibly you did a few times already, and that probably wouldn't be the case if the idea was that ground-breaking, that unprecedented.

Ok, nevermind - I'm getting angry for no reason, I should stop it already.

Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by dragonwriter on Monday January 05, 2015 @02:38PM (#8840633)
> You desperately insist on giving them meaning.

They have meaning in the same sense that any words have meaning -- that is, they communicate meaning between an existing group of people.

> And sometimes, which is worse, the meaning you want to give them is completely unrelated or even opposed to everything they are or do.

Like many words, their meaning in a specific technical context differs from their meaning in other contexts. This is not particularly unusual.

> Aside: You realize that the word "monad" (and "dyad") already has a very specific meaning

"Monad" has several distinct well-established meanings in different domains besides its use is Category Theory (and thus Haskell). So what?

> and that you assaulted that meaning and now are trying to beat the poor word into submission?

The meaning of "monad" in Haskell comes directly from its meaning in Category Theory, which is inspired by (though not the same as) its earlier use in mathematics stretching back to its use in metaphysics (particularly, through Leibnitz's Monadology), which has its roots in its use in Classical philosophy, from whence also comes all its other uses.

> If I had to choose I'd say that J programmers have much more of a right to use and define this word

Well, you don't have to or even get to choose that; words can and do have uses in different contexts and you don't get to choose one and make it the exclusive use of the word because you like it more.

> a single-argument function ("mono") makes more sense to be called a "monad" than an instance of "flat-mappable" interface.

Not really. Sure, a single argument function might have a better claim to the title "mono-argument function" but "-ad" isn't generally a suffix that means "-argument function".

Re:Monoids, Functors, Applicatives, and Monads: Main Ideas by klibertp on Monday January 05, 2015 @05:05PM (#8841524)
Ok, so I was rather rude unnecessarily, sorry about that. I agree with what you wrote about words:

> words can and do have uses in different contexts and you don't get to choose one and make it the exclusive use of the word because you like it more.

it's just that I think the same applies to concepts. You shouldn't be able to "own" the concept and to insist that it should be called as you want in every context. I see comments and posts about how "X or Y is just a monad!" to be exactly this: people trying to "own" a concept.

Just as both musicians, mathematicians and programmers can all use a single word for different things, different programmers should be able to use the same concept without using the same word for it.

In short (directed to random commenters on the Internet, no to you personally): stop correcting me when I say "computation expression builder", don't say that what I "really mean" is a monad. It's not, what I "really mean" is an abstract concept and we both know its properties, and you have no right to oppress me because I chose different word for it.