Learn to love LINQ

The final talk by Erik Meijer, in which he again will try to explain monads, since the previous attempt might not have succeeded for everyone.

For database people SQL queries are turned into relational algebra. So they turn a pretty syntax into primitive operations. It was created by Codd, who was neither a programmer nor a category theorists and that shows.

Because we could ask: why just sets? Why tuples/rows? He should have answered the question what the interface is that relational algebra implements.

So let’s fix this and create an interface for relational algebra

Empty set::M<T>
Union:: M<T>xM<T>-> M<T>
Create :: T -> M<T>

Plus algebraic laws like the empty set is the nul element for union etc.

Now we can define functions
Filter :: M<T> x (T-> Bool) -> M<T> But this has nothing to do with sets, we could do this for trees or dictionaries or whatever.

X :: M<T>xM<T> -> M<TxS> Takes a tuple of collections and turns in into a collection of tuples. There is one more important twist.

SelectMany :: M<T> x (Expr<T -> M<S>>) -> M<S> where (Expr<T -> M<S>>) is a representation of afunction. And this is exactly what LINQ is.

Now, do you recognise the monads?

M<_> = Functor

SelectMany = Bind

{_} = return