foreword

For the past couple of decades, object-oriented programming has dominated the industry, its ability to hide complexity and provide structure and intuition providing a major boost to software development.

Not all kinds of complexity submit willingly to the mechanisms of encapsulated shared state and virtual methods. Some domains of computation, analysis, and transformation were not much helped by objects, and, looming bigger every day, the demand for concurrency is placing new pressure on the object-oriented paradigm.

From an obscure existence in academic institutions and research labs, functional and declarative techniques have gradually crept into mainstream languages to counter those challenges. In C#, for instance, we added generics, anonymous functions, and monadic query expressions. But a full-fledged commercial functional programming language with the extensive libraries and tools that are crucial to developer productivity has been lacking. I believe F# is a magnificent milestone: one of those turning points that we will look back on and say that’s when we turned the corner.

F# reaches back pragmatically over the language divide, comfortably embracing the full object model of the .NET framework. But now, we have to distinguish between functional programming and functional programming languages. As languages become multi-paradigmatic, what used to be a binary choice up front (object-oriented or functional) morphs into a broadened set of opportunities at every turn in your program. You can use functional programming techniques in C# to great benefit, though it is easier and more natural to do so in F#. You can settle on a preferred flavor in your choice of programming language, but your problem-solving options remain open.

The great genius of this book is how it teases apart the functional mindset from the F# language itself. By showing both the C# and F# embodiments of functional programming patterns, the reader is well served. The developer who wants to embark on coding in F# gets a leg up from seeing the patterns used in a (presumably) familiar language. The programmer with good reasons to stay in C# can appreciate the principles in their pure form from the F# examples.

Functional programming is a state of mind. It is a way of thinking differently about the problem. It is not just a bag of useful tricks (though it is that too), but a perspective from which the gnarliest knots prove to be approachable. In this book, as practical and hands-on as it is, Tomas and Jon gently and bravely insist on stressing the principles underneath. Read it at your own peril; you will never look at your own code the same way again!

Mads Torgersen
C# Language Program Manager
Microsoft Corporation