I’m really interested in learning more about functional programming. It isn’t something I knew much about, but the benefits of reducing mutability (and shared state) promoted by functional languages and functional style are enticing.
To that end, I recently bought a copy of Isaac Abraham’s new book “Get programming in F#. A guide for .NET Developers”.
I have no background in functional languages at all, so I was looking for a “gentle” introduction to the F# language, without getting hung up on a lot of the functional terminology that seems to make learning this stuff a bit impenetrable for the newcomer. This book delivers.
The structure of the book is in 10 “units”, which in turn are broken down into separate “lessons” (each lesson is a separate chapter).
Here’s my notes from each unit:
Unit 1 – F# and Visual Studio
- Introduces using the Visual Studio IDE for F# development, and recommended extensions. Surprisingly for a book published in 2018, most of the book is based on using Visual Studio 2015. I can only presume this is an artifact of the time it takes to write a book. I understand the initial release of 2017 did have some tooling regressions for F# but I am under the impression those are now resolved, seeing at my time of writing the 7th update for 2017 has just been released, including specific enhancements for F#.
- Throughout the book, comparisons are made to equivalent C# language constructs, and here too, the text is already a bit dated. An unfortunate downside of a printed book I guess.
- One thing to note that is different from many other languages – the file order in F# projects is significant. You can’t reference something before the compiler has seen it, and the compiler processes files in project order.
- The REPL is also a big part of F# development.
Unit 2 – Hello F#
- The ‘let’ keyword is introduced. It’s more like C#’s const than var, seeing as F# defaults to things being immutable rather than mutable.
- Scoping is based on whitespace indentation rather than curly braces.
- Diving into how the F# compiler is much stricter because of the way the F# type system works, and how that can be a good thing.
- A closer look at working with immutable data, and how you can opt in to mutable data when absolutely necessary, and how to handle state.
- C# is statement based, whereas F# likes to be expression based.
- The ‘unit’ type is introduced. It’s kind of like void, but is a way for expressions to always return a value (and means the use of those expressions is always consistent).
Unit 3 – Types and functions
- Tuples, records
- Composing functions, partial functions, pipelines,
- How do you organise all these types and functions if you’re not using classes? Organising code through namespaces and modules
Unit 4 – Collections in F#
- Looking at the F#-specific collection types – List, Array and Seq, the functions you can use with those collections. Immutable dictionaries, Map and Sets. Aggregation and fold.
Unit 5 – The pit of success with the F# type system
- Conditional logic in F#, pattern matching
- Discriminated unions
Unit 6 – Living on the .NET platform
- How to use C# libraries from F#. Using Paket for NuGet package management
- How to use F# libraries from C#
Unit 7 – Working with data
- Introducing Type Providers. Specific use cases with JSON, SQL and CSV.
Unit 8 – Web programming
- Asynchronous language support
- Working with ASP.NET WebAPI 2
- Suave – F#-focussed web library
- Consuming HTTP data
Unit 9 – Unit testing
- The role of unit testing in F# applications
- Using common .NET unit testing libraries with F#
- Property-based testing and FsCheck
- Web testing
Unit 10 – Where next?
- Further reading and resources to take your next steps.