Demystifying Monads

Recorded at:

Summary
Josh Graham explains what monads are, how and why they are used, including several concrete examples of monads like Identity, Maybe, List, and Continuation. (This session is based on Amanda Laucher’s presentation “Demystifying Monads.”)

Bio

Josh Graham, ThoughtWorks, has over 19 years experience in the software industry and is the Chief Dispenser of Pleasantries at ThoughtWorks. Graham has spoken at and chaired conferences on SOA, enterprise architecture, agile software delivery, and technology innovation.

QCon is a conference that is organized by the community, for the community.The result is a high quality conference experience where a tremendous amount of attention and investment has gone into having the best content on the most important topics presented by the leaders in our community.QCon is designed with the technical depth and enterprise focus of interest to technical team leads, architects, and project managers.

This doesn't work, because it would you imply you could pass a function returning *any* monad, whereas you must necessarily be able to pass only a function returning the type of monad you're working with. So you can write an interface for specific monads (Maybe shown below), but not the general monad interface.

This interface is fine. Now generalize it to List. There's no common superinterface of these two that can exist, because you can't abstract over the type constructor as we do in the Scala example.

I know from recent experience that trying to give presentations on monads accessible to a broad audience is bloody difficult and frustrating. The problem is twofold; first, the "monad tutorial fallacy" issue of understanding of monads only being arrived at through use of monads is a huge hurdle - it's hard to take on faith that if you start using monads without really understanding how they work (because you must do so, in order to understand them!) will genuinely pay benefits. Second, in order to make good use of them, you've got to be writing code in an environment that supports using them, which means you have to step away from mainstream languages; Java, C++ and C# (which I suppose are the three most commonly used languages that actually support parametric polymorphism) don't support higher-kinded types, and dynamic languages miss a lot of the benefits of using monads simply because being able to reason about a computation via the types are where a lot of the benefits from using monads come from. So you have to go to Scala or F# or Haskell, and then you have to get used to thinking in types, and you have to do all of this without knowing ahead of time what the benefits will really be.

From your explanation a Java programmer already gets a better intuitive feel about the concept. I think that for something like this one should not refrain from "adding" the needed features to a language. If you need to be able to pass function around just add this missing feature to Java for the sake of the presentation. Explain the syntax you will use and then proceed with the explanation. Of course this can work only if the parts that are missing are few. If you need to add too much to the language then it becomes useless.Thank you for your input.

Do you have a personal vendetta with this presenter? Where did you learn to communicate? Regardless of what you think of the presentation and presenter, it is you sir who comes across as the $%#hole. Let me guess, you are an American on East or West Coast? I would bet East...