The F# Survival Guide
by John Puopolowith Sandy SquiresIntroduction
The F# Survival Guide
. The purpose of this Web book is to provide a solid foundation and pragmatic introduction toF# programming and its functional underpinnings.
I wrote this book with the intent that it is the first book you read in your F# journey.
Along these lines, this book covers the entirety of the core F# language, as available November 2009. It covers all of the documented (and some of the lessdocumented) concepts, keywords, constructs, types, and language symbols. In addition, I have tried to provide short examplesthat capture the essence of the topic at hand, while at the same time discussing real-world impacts. My hope is that after readingthis book, you will be able to develop non-trivial applications using F#, and will be able to readily extend your learning viaadditional resources.
Why This Book?
While there are several books in print, and some Web-based resources for learning F#, I have not found a single one that'saltogether
and easily digestible by mainstream developers
. Few, if any, of these resources takes a bottoms-upapproach, methodically building up a conceptual and practical framework that builds skills and confidence in a systematic way. Additionally, most of the F# materials that I've read are to some extent academic, with a bent towards describing F# in terms of esoteric constructs (check out the
monad on the Web for a good dose of newbie confusion!). In my (humble) opinion,much of the existing material doesn't resonate naturally with OO application developers. These are the issues that I've tried toaddress with this book. Also, whenever I read technical books, I ultimately have questions that roll through my head as I go. The books I tend to loveanticipate my "rolling questions" and answer them quickly and clearly. I will do my best to anticipate your rolling questions andanswer them in kind. I've also made it a point to keep the chapters relatively short, covering one or two related topics at a time.Lastly, I tend to dislike books that introduce new concepts and syntax without first establishing a solid foundation. One of thegoals I have for this book is to wait until I've covered a topic before using it in examples, etc. I get frustrated when books throwin a new concept in the middle of an example – it's very distracting and usually takes away from the point that the author istrying to make. Therefore, I will use data structures, syntax and concepts only after we've discussed them. Because certainlanguage features are so highly interconnected, this may not always be possible; however, I think we can go a long way here.Instead of lamenting over the dearth of palatable materials and complaining about what I don't like (that's too easy), I've decidedto do something about it and contribute to the development community as best I can. I've chosen this particular topic because Ifeel quite strongly that functional programming will play prominently in the next decade of computing. Why? Two words:multicore processors.In order to increase compute speeds and throughput cycles, technology manufacturers such as Intel, AMD, Dell, HP, etc. havetaken to shipping computers with multiple CPUs and CPUs with multiple cores. Given this trend, it is not unreasonable to assumethat near-future desktops will contain 8, 16, 32 and more cores. Beyond the desktop, there is "the cloud", with virtuallyunlimited computing resources available.In order to take advantage of all this computing power, we developers will need to think differently about how we design andwrite our software. I feel this way because writing concurrent, multi-process, multithreaded, asynchronous applications is alreadyfamously difficult, and it will only become more so with the continued scale and adoption of compute-rich hardware.By learning functional programming concepts in the context of a rich, fully-supported language and tool chain, and learning howto apply these properly, you are well on your way to preparing for the next generation of software development.
This book is intended for professional software developers, students of computer science, and advanced enthusiasts who want togain a foundation in functional programming and fluency in F#. It will be especially useful to those coming from a mainstreamimperative/OO background. I have found that the "functional guys" love to explain things in mathematical and sometimes obtuseterms. I don't think that it's intentional – it stems from what the Heath brothers call "the curse of knowledge" in their (wonderful)book
Made to Stick
. Coming from an imperative/OO background myself, I know how "we" think about problems, hopefullyexplaining things in terms that are somewhat familiar and comfortable to you.I assume that you have developed software in the past, and have a working understanding of fundamental programmingconcepts such as variables, conditional structures, expressions, loops, collections, linked lists, etc. You will have programmed inC, C++, Python, etc. I also assume that you are familiar with at least one object-oriented language such as C++, C#, Java, etc.