Gilad and Erik. Same place. Same time. A coincidence that *demanded* an Expert to Expert session. They kindly agreed to be put into the spotlight (literally) for a C9 conversation. Here's what happened...

Giladism #42: "Mathematicians love to explain things backwards."

Giladism #43: "There is a huge role for mathematical abstractions in programming languages. It's just that you have to know when to shut up about them and stop taking them as religion."

Some highlights:

[00:00] State of programming language design today

[05:01] On actors

[08:28] Dart snapshot facility

[34:07] On monads

[42:26] On continuations and when to hide mathematical complexity from users

Tune in. Enjoy.

Huge thanks to Gilad and Erik for this excellent conversation!

Here, we talk about functional programming—when to go functional and why—and Tony addresses some of the problems that face developers who want or need to go functional but possess only an imperative way of thinking when it comes to designing and writing software. It's the functional way of thinking that most newcomers to functional programming find most difficult. Of course, there's no conversation about functional programming without talking about monads, so we talk about monadic design (and definition).

Thanks for joining us on C9 Tony!

The **YOW! Developer Conference** offers outstanding opportunities to learn more about the latest practices, technologies, and methodologies for building innovative software solutions as well as the chance to meet and network with international software experts and other talented developers in Australia. Thanks to **Dave Thomas** and the event's *excellent* staff—**Mary Catherine (MC), Lisa, Aino, Melissa**, and others—for inviting me to this *excellent* pure developer event and thanks to all of the speakers for letting me take some of their time to record conversations for Channel 9. If you live in Australia, or aren't too far away, or just like to travel (who doesn't?), then you need to go to this yearly event. It's outstanding. There are many great developers down under. That's for sure. The speakers are exceptional—Dave and team set a high bar!

The fundamental concept here is the monad, and Greg has a novel and conceptually simplified explanation of what a monad is and why it matters. This is a very important and required first step in the series since the whole of it is about the application of monadic composition to real world web development.

In **part 4, **Greg primarily focuses on the idea that *a monad is really an API—*a view into the organization of data and control structures, not those structures themselves. In OO terms, it's an *interface*. To make this point concrete, Greg explores one of the simplest possible data structures supporting at least two different, though consistent, interpretations of the same API. The structure used, Conway's partisan games, turns out to be tailor-made for this investigation. Not only does this data structure have the requisite container-like shape, it provides opportunities to see just what's necessary in a container to implement the monadic interface.

Running throughout the presentation is a more general comparison of reuse between an OO approach and a more functional one. When the monadic API is "mixed into" the implementing structure, we get less reuse than when the implementing structure is passed as a type parameter. Finally, doing the work puts us in a unique position to see not just how to generalize Conway's construction *monadically*, but also the underlying pattern that allows the generalization to suggest itself.**Source code for the Conway game****Slides for this presenation**

Why *bananas*, Ralf?

*Banana *is functional programming slang for "fold"—an application of the catamorphic recursion scheme most widely known in the higher-order list processing tradition of Bird-Meertens Formalism and the Squiggol community. Erik Meijer used to be known as the "banana man" because of his early research on the subject; he also co-authored the seminal paper with theoretical (categorical) foundations on the subject. Incidentally, the paper used the notation of so-called "banana brackets" (instead of using the plain string "foldr"), which sort of explains why we sometimes say bananas. There is no shortage of crazy paper titles on the subject, by the way: "Functional Programming with Bananas, Lenses, Envelopes, and Barbed Wire," "Bananas in Space: ...," "Dealing with large bananas," "Boxes go bananas: ...," "See more through lenses than bananas," etc.

More to the point, ** foldr** is the Swiss Army Knife in functional programming. Monoidal reductions of lists or mapping over lists and many other list-processing idioms can be modeled with the regular recursion operator

**Learn more:Going Bananas lecture slide deck**

Ralf's blog

For the exercises/riddles in the slide deck:

12 (medium)

18 (medium)

21 (medium)

23 (easy)

24 (hard)

31 (hard)

34 (easy)

The fundamental concept here is the monad, and Greg has a novel and conceptually simplified explanation of what a monad is and why it matters. This is a very important and required first step in the series since the whole of it is about the application of monadic composition to real world web development.

In **part 3**, Greg continues to take us on a monadic journey, en route to the design of a composable web stack from client to database. This series is specifically about monadic design patterns and not implementation details using Scala and asscoiated dev tools. Open your minds and let the design pattern knowledge in.

Shape. Wrap. Roll.

]]>The fundamental concept here is the monad, and Greg has a novel and conceptually simplified explanation of what a monad is and why it matters. This is a very important and required first step in the series since the whole of it is about the application of monadic composition to real world web development.

In part 2, Greg continues to take us on a monadic journey, en route to the design a composable web system from client to database and back. Tune in. Learn.

Shape. Wrap. Roll.

See **part 1 **first, if you haven't already...

See **part 3**

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

]]>Today, Ralf Lämmel's lecture goes back to the roots, essentially revisiting Wadler's "The essence of functional programming"—the 1992 paper that discovered monads and popularized their use in functional programming. Ralf Lämmel's lecture and accompanying code distribution show Wadler's seminal insight: those original scenarios and observations still make sense today. Indeed, Simon Marlow (a Haskell/GHC high priest @ MSR Cambridge) recently noted: "it's still the best monad tutorial" (see http://twitter.com/simonmar/status/21397398061).

Focusing on a few generically useful monads, Dr. Lämmel explains how the work within the interpretation domain. While the lecture also takes a look at the contemporary Haskell library for monads and monad transformers, there are obviously many monads and associated domains that cannot be covered this time. If you want to learn more about monads, then continue with state threads, IO, parsing, and concurrency (STM).

Slide deck:

Exercises/riddles:

Slide #4 (easy), #6 (modest), #13 (modest), #40 (hard)

Code distribution:

Blog post:

http://professor-fish.blogspot.com/2010/09/essence-of-essence-of-functional.html

]]>The idea for the format of this conversation is simple: put two geniuses together, give them each a whiteboard and some markers, and see what happens. It's much like free jazz: expert improvisation, seriously geeked-out whiteboard jamming.

The content theme for this episode--Monads as coordinate systems--is not simple. To grok this, we need to think in three dimensions: programming, physics and mathematics. But don't worry. Brian and Greg do not expect to be jamming in front of only fellow experts. This is Channel 9, after all, and there are many different levels of knowledge out there amongst our Niner population. Accordingly, you will not feel as though you're watching something in a language you don't speak. That said, you should possess interests in the theoretical, in mathematics, and in physics, and an overall appreciation for learning new things.

This is a fantastic whiteboard jam session with two very interesting, very bright, and very knowledgeable experimental theoreticians . Enjoy!

Link to Huet's Zipper paper. ]]>

Enter astrophysicist and monadic composition wizard Brian Beckman. The last time Brian was on C9 he taught us about the State Monad. At the end of that discussion he mentioned he wanted to teach us about the Continuation Monad next. So, who better to conduct this episode of Expert to Expert than Dr. Beckman? Yep. You guessed it! Rx employs the Continuation Monad in its composition. Erik is in the hot seat this time and it's always a real pleasure to converse with Erik and Brian in the same room at the same whiteboard.

Now, what is Rx?

The .NET Reactive Framework (Rx) is the mathematical dual of LINQ to Objects. It consists of a pair of interfaces IObserver/IObservable that represent push-based, or

interface IObservable<out T>

{

IDisposable Subscribe(IObserver o);

}

interface IObserver<in T>

{

void OnCompleted();

void OnNext(T v);

void OnError(Exception e);

}

Observable collections capture the essence of the well-known subject/observer design pattern, and are tremendously useful for dealing with event-based and asynchronous programming, i.e. AJAX-style applications. For example, here is the prototypical Dictionary Suggest written using LINQ query comprehensions over observable collections:

IObservable<Html> q = from fragment in textBox

from definitions in Dictionary.Lookup(fragment, 10).Until(textBox)

select definitions.FormatAsHtml();

q.Subscribe(suggestions => { div.InnerHtml = suggestions; })

Please subscribe to this Channel 9 interview to be notified when we have clearance to distribute Rx over the counter (lame puns intended .

Tune in. This should prove to be an instant classic besides being a very important episode of E2E. Rx is deep, man. Deep.

Enjoy! ]]>

This is another great conversation with astrophysicist and programming master Brian Beckman. Brian is one of the true human treasures of Microsoft. If you don't get mondas, this is a great primer. Even if you don't care about monadic data types, this is worth your time, especially if you write code for a living. This is part 2 of a 2 part series.

Below, you will find several exercises for generalizing the constructions further.

to <S>, say, so that the SM type can handle any kind of

state object. Start with Scp<T> --> Scp<S, T>, from

"label-content pair" to "state-content pair".

**Exercise 2**: go from labeling a tree to doing a constrained

container computation, as in WPF. Give everything a

bounding box, and size subtrees to fit inside their

parents, recursively.

**Exercise 3**: promote @return and @bind into an abstract

class "M" and make "SM" a subclass of that.

**Exercise 4 (HARD)**: go from binary tree to n-ary tree.

**Exercise 5**: Abstract from n-ary tree to IEnumerable; do

everything in LINQ! (Hint: SelectMany).

**Exercise 6**: Go look up monadic parser combinators and

implement an elegant parser library on top of your new

state monad in LINQ.

**Exercise 7**: Verify the Monad laws, either abstractly

(pencil and paper), or mechnically, via a program, for the

state monad.

**Exercise 8**: Design an interface for the operators @return

and @bind and rewrite the state monad so that it implements

this interface. See if you can enforce the monad laws

(associativity of @bind, left identity of @return, right

identity of @return) in the interface implementation.

**Exercise 9**: Look up the List Monad and implement it so that it implements the same interface.

**Exercise 10**: deconstruct this entire example by using

destructive updates (assignment) in a discipline way that

treats the entire CLR and heap memory as an "ambient

monad." Identify the @return and @bind operators in this

monad, implement them explicitly both as virtual methods

and as interface methods.

This is another great conversation with astrophysicist and programming master Brian Beckman. Brian is one of the true human treasures of Microsoft. If you don't get mondas, this is a great primer. Even if you don't care about monadic data types, this is worth your time, especially if you write code for a living. This is part 1 of a 2 part series.

Included with this interview is a .zip file containing all of the code and diagrams Brian shows us (including both Haskell and C#). To understand the State Monad program, it may be best to start with Main, seeing how the various facilities are used, then backtrack through the code learning first the non-monadic tree labeler, starting with the function Label, then finally the monadic tree labeler, starting with the function MLabel.

Below, you will find several exercises for generalizing the constructions further. Brian will monitor this thread so start your coding engines!!

E

Of course, learning new ways to think about programming semantics and code patterns are not always straight forward. For example, most imperative programmers (which include most of us who build software for a living...) are somewhat perplexed by the notion of functions as first class data structures that can be combined to create powerful and composable systems. Languages like Haskell are pure functional languages and require programmers to think in a different way, often in a precise mathematical fashion where composing and chaining functions is "the Way".

Dr. Brian Beckman, a Channel 9 celebrity, astrophysicist and senior software engineer thought it would be a very good idea to address the complexity of monads in an easy to understand way: a technical conversation at the whiteboard with yours truly for Channel 9.

This video interview is the result of Brian's idea that he can in fact remove the fear of monads from anybody who pays attention to his explanation. Of course, you can't just cover monads in a vacuum (category theory is not really addressed here) so the context is

Tune in. There's a lot to learn here and only Brian can make monads easy to understand for the rest of us!

Happy Thanksgiving to all the US Niners out there.

Enjoy. ]]>

Brainbec's Weblog

]]>