# C9 Lectures: Greg Meredith - Monadic Design Patterns for the Web - Introduction to Monads

- Posted: Sep 28, 2010 at 9:32AM
- 66,890 views
- 19 comments

Loading user information from Channel 9

Something went wrong getting user information from Channel 9

Loading user information from MSDN

Something went wrong getting user information from MSDN

Loading Visual Studio Achievements

Something went wrong getting the Visual Studio Achievements

- Posted: Sep 28, 2010 at 9:32AM
- 66,890 views
- 19 comments

- To download, right click the file type you would like and pick “Save target as…” or “Save link as…”

- It's an easy way to save the videos you like locally.
- You can save the videos in order to watch them offline.
- If all you want is to hear the audio, you can download the MP3!

- If you want to view the video on your PC, Xbox or Media Center, download the High Quality MP4 file (this is the highest quality version we have available).
- If you'd like a lower bitrate version, to reduce the download time or cost, then choose the Medium Quality MP4 file.
- If you have a Windows Phone, iPhone, iPad, or Android device, choose the low or medium MP4 file.
- If you just want to hear the audio of the video, choose the MP3 file.

Right click “Save as…”

- High Quality WMV (best available)
- MP3 (Audio only)
- Low Quality MP4 (approx. 500-800kbps)
- Mid Quality WMV (Lo-band, Mobile)

Greg Meredith, a mathematician and computer scientist, has graciously agreed to do a C9 lecture series covering monadic design principles applied to web development. You've met Greg before in a Whiteboard jam session with Brian Beckman. The fundamental concept is here is the monad.

Greg has a very novel and conceptually simplified explanation of what a monad is and why it really matters. This is very important and a required first step in this series since this is all about the application of monadic composition to real world web development. What does this mean? Why does it matter?

Tune in.

Let's see if Greg's monadic analogies prove helpful for everyday developers in getting their heads around the elusive and beautifully complex monad.

Shape. Wrap. Roll.

See part 2

Comments have been closed since this content was published more than 30 days ago, but if you'd like to continue the conversation, please create a new thread in our Forums, or Contact Us and let us know.

## Follow the discussion

Oops, something didn't work.

## What does this mean?

Subscriptions allow us send you email notifications when new content is added. You need to be signed in to Channel 9 to use this feature.## What does this mean?

Subscriptions allow us send you email notifications when new content is added.sign up for email notifications?

This is going to be good! Downloading now ...

Thanks to Greg and Charles for what will surely be another great lecture series.

Great! Greg, I visited your website ( biosimilarity.com ) a few days ago and I read you organise workshops onMonadic Design Patterns for the Web. I wanted to write you an email and ask if you have any video about this for the ones who can't attend your workshops... and now we have it!

Superb! I love the names (I guess Shape is Mr. T (or M<T>; does that pronounce "em-tee"?), wrap is return and roll is bind, aka SelectMany and map is Select). Looking forward to seeing where this is going.

I'm having flashbacks to Brian's clock mon

oidThe design-by-contract mention is also very interesting.

So far my understanding is that...

Roll doesn't really make sense for integers and clocks because there's not really any useful structure to flatten, so it becomes a no-op. For sets and lists yes because they can nest. Need to look a little more at the laws - but I love the way you "level" them.

Greg, didn't you mean strings are monads - as conceptually they are just lists of characters and therefore just a particular kind of list.

As Charles would say, if he was trapped in a monad:

"

Wrap 'n Roll!".@exoteric: I love Greg's analogies and he's a

tremendousteacher. We are all in for a real educational treat.Thank you, Greg.When you think about it; where else on the planet can you get educated, for free, by the likes of Erik Meijer, Brian Beckman, Stephan T. Lavavej, Greg Meredith, Yuri Gurevich and Don Syme? We are very fortunate. We'll have more lectures by titans of the industry, too. It's humbling to be a part of this.

Keep on learning. Stretch your minds.

Here's to Future 9.

C

Great video, looking forward to the next adition... please don't keep us waiting too long

@exoteric: Interesting that you said that Unit is 0. In the video unit is 1. This is something that confused me. It was unclear to me if the operator applied to the unit was increment or the unit meant to be identity.

I took it that it was meant to be the smallest incremental unit, especially since the unit was 1 and the operator was '+', rather than '*'.

@Ken Jackson: I had to do a little Wikipedia'ing -

A monoid obeys 3 axioms:

closure: whenever we compose two integers (+) we get another integeridentityelement: for integer addition (+) this has to be 0; for multiplication 1 ...associativity: (a + b) + c = a + (b + c);for integers this should be true

(1 + 2) + 3 = 1 + (2 + 3);

but actually for lists too!

([1,2] + [3,4]) + [5,6] = [1,2,3,4,5,6] = [1,2] + ([3,4] + [5,6])

So actually lists and by proxy strings (lists of characters)

are indeedboth monoids but as opposed to integers under addition, lists (under append)are notcommutative.I guess we could also say that we have an "

integer multiplication monoid", in that case:closure: multiplying two integers gives another integer --checkidentityelement: 1 since 1 * a = a --checkassociativity: (a * b) * c = a * (b * c) --checkOne thing I take away from this (perhaps wrongly) is that just saying "integer monoid" is misleading or ambiguous since there appears to be several ones, depending on what composition operator you choose (+, *, ...)

By the way - Greg is mentioned in the wikipedia article for monads

@Exoteric: In your defintion of the "integer monoid" (a.k.a. monoid of natural numbers with + and 0) you call u "unit". I find that a bit confusing as in the context of monads "unit" is often used synonymously for "return". On the other hand in algebra unit refers to a multiplicative identity element. I'd therefore prefer the term

neutral element(or identity element) for u.Again, great lecture! I'm looking forward to more!

@Novox: You're right, unit is confusing and misleading; it's as confusing as zero. So yes, i for identity would work better (I hope); fixed.

So is the monad the total off the three parts or the process of the three parts?

Timing is a wonderful thing, as I'm starting to get the idea with the help of the below link.

http://www.lostechies.com/blogs/derickbailey/archive/2010/09/29/monads-in-c-which-part-is-the-monad.aspx

Really enjoyed the lecture. People might also want to check out Dan Piponi's "monads as trees" http://blog.sigfpe.com/2010/01/monads-are-trees-with-grafting.html. Also this talk is a must see: http://vimeo.com/6590617.

Hi Everyone!

Thank you Greg for a fantastic introduction to Monads and thanks Charles for making it happen. Great stuff!

I think I finally get a deeper understanding of what a monad is and would like to share an interesting revelation that I had connected with it. I realise what I say may sound somewhat strange but to me:

Monad = LIFE!

Hehe, let me elaborate...well generally speaking monad = change, I like to compare it to a transformation in life, we all go through different stages (wraps) in life and we need means (bind aka roll), in order to get from one stage to another.

It goes quite well with the KISS philosophy as well, the more complicated, scattered our life is, the more unmaintainable it is. What one would like to achieve, is to make his life simpler by taking out the unnecesary fuzz (scattered wraps) out of his life, thus ultimately creating a happier (monadic) version of life for himself, by using a kind of monadic transformation.

In that senese, to me the most difficult part of a monad would be the bind operator then, since this is were the transformation happens. In programming, just as in life, there is not one, universal bind operator, which forces us to come up with customized solutions for both our programs and lives.

Keep the lectures coming, I wonder where the next one will take me;)

I've turned my learning into an evolving blog post.

http://xosfaere.wordpress.com/2010/10/05/shapely-monads/

Thanks for the great brain wash!

PS - looks like Greg's written a book about this:

http://www.amazon.com/Pro-Scala-Monadic-Design-Patterns/dp/143022844X

This is good stuff. On future slides can you use green or yellow instead of red? It doesn't show up very well ...

Thanks for posting this!

Great lecture - very enlightening and worth watching several times over.

Any news on when the next installment is likely to be available ?

Greg is coming to the C9 Studio to film the next part tomorrow, so we'll have it available not too long after that (probably next week sometime).

C

@Charles: Can't wait for the next instalment to be available, keep up the good work!

I am still confused. Is there a more practical example? Like how does this make coding eaiser, clean, easier to maintain and so on?

It is all very amazing, just mindboggling

## Remove this comment

## Remove this thread

Close