BT

Facilitating the Spread of Knowledge and Innovation in Professional Software Development

Write for InfoQ

Topics

Choose your language

InfoQ Homepage Presentations Demystifying Monads

Demystifying Monads

Bookmarks
01:01:05

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.

About the conference

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.

Recorded at:

Aug 11, 2010

Hello stranger!

You need to Register an InfoQ account or or login to post comments. But there's so much more behind being registered.

Get the most out of the InfoQ experience.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Community comments

  • Horrible presentation. Total waste of time

    by Sebastian Kübeck,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    remember that even if you are working for ThoughtWorks you should have a clue about what you are talking about and you should take some time to prepare presentations.

  • If monads are Patterns then the examples could have been in Java

    by jean-simon Larochelle,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Or any other maintream language (C#, C++). F# is really not mainstream and looks like APL to me. Because of this the examples were useless and the presentation lost much of its interest.

  • Absolutely Horrible Presentation

    by Jordan Terrell,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    This presentation should be considered harmful. You will end up being more confused than when you started, and it makes many incorrect or misleading statements. I vote that it be removed from InfoQ.

  • Re: If monads are Patterns then the examples could have been in Java

    by Kris Nuttycombe,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Actually, you can't represent the the general monad type in Java; the type system isn't rich enough to do so. You need higher-kinded types to express the monadic type.

    In Scala, the monadic type looks like this:


    trait Monad[M[_]] {
    def pure[A](a: A): M[A]
    def bind[A, X](m: M[A], f: A => M[X]): M[X] //aka return, aka >>=, aka flatMap...
    }


    See the A => M[X] part? Let's try to construct a monad interface in Java


    interface Monad<A> {
    public <X> Monad<X> bind(F<A, Monad<X>> function);
    }


    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.


    interface Maybe<A> {
    public <X> Maybe<X> bind(F<A, Maybe<X>> function);
    }


    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.

  • Re: If monads are Patterns then the examples could have been in Java

    by Kris Nuttycombe,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    oops, that "//aka return" was supposed to be up a line

  • See. That's better already

    by jean-simon Larochelle,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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.

  • FUGLY presenter!

    by Ivan Salazar,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Beautiful language and patterns he's *trying* to explain but he's like a zombie trying to talk about vegetarianism. Kick this asshole out and read this Simon Peyton-Jones paper: research.microsoft.com/en-us/um/people/simonpj/... .

  • Re: FUGLY presenter!

    by Michael Apostol,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    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...

    Get some manners. You come across like a child.

  • Re: FUGLY presenter!

    by Ivan Salazar,

    Your message is awaiting moderation. Thank you for participating in the discussion.

    Sorry.

    I tend to overreact when Haskell is being misrepresented. And no, I'm not an American. And yes, in this particular one, I looked like a child. Your reply helped me to put myself in perspective.

    Thanks, and sorry again.

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

Allowed html: a,b,br,blockquote,i,li,pre,u,ul,p

BT