Other posts in the series:

  • Part I - Background
  • Part II - Tuples
  • Part III - Records
  • Part IV - Type Unions
  • Part V - The Match operator
  • In December (slow time in msft) I decided to understand what functional programming is all about. When I say 'understanding' I don't mean just paying lip service to the main concepts by knowingly mentioning them in casual conversations (i.e. "look at this memoization, man!" or "this lambda function is so hot!". I can already do that. I intellectually know what the thing is.

    I wanted to *really* understand it. For me that means writing plenty of code. I had a medium size application in my mind that I've been wanting to write for quite some time (stock price, dividends, splits downloading and various return calculations), so I went ahead and wrote it. I also wanted to use C#. It would have been easier in F#, but I work on the C# team and love using our own product.

    My early attempts were unpleasing. I would fall back to my OO background and my functional code slowly reverted to OO code. My way of thinking about it, even if starting with the best intentions, would go back to: what are the objects, what are their responsibilities and such.

    I needed to force myself somehow; kind of overcompensate on the other side. I hit on the idea of pragmatically defining functional programming and try to limit myself to the subset of language constructs inside my definition. As a way to define it, I used Chapter 3 of "Expert F#". I know, I know, I could have read 1,000s of academic papers and come up with a meta-analysis of all of them that formally defines what 'functional programming' really is. But life is too short. I trusted Don.

    The problem is, several of the language constructs in my small definition of functional programming don't exist in C#. So I went ahead and created them. I built a little library to represent them and forced myself to write code using just this library. It worked.

    In this series of posts I will describe what's inside this library. I want to emphasize that I built it for educational purpose only, not for performance or production code. Caveat emptor.

    My plan is to cover the following:

    1. Tuples
    2. Records
    3. Type Unions
    4. Match

    Let's see if I can find the time to actually write these posts :-)