Unit 3. Types and functions

 

So far, in terms of F# the language, you’ve looked at type inference, structuring code with expressions, and working with immutable data. But you’ve only dealt with simple data values—int, string, and so on. What about classes? Do we still have them in F#? If not, what else do we use? And what about functions? F# is supposed to be a functional programming language, and yet we’ve barely covered them!

Don’t worry: this unit covers all these topics. You’ll see how F#’s approach to separating data and behavior works, and why it generally means that classes are undesirable within a functional-first system. In fact, this unit doesn’t focus on classes at all. Instead, it presents alternative ways of modeling problems without needing to resort to classes. (And believe me when I say I’ve written entire full-stack applications in F# without needing to write a single class!)

You’ll see how the rules you learned about immutable data still apply, even when working with larger data structures. You’ll also learn more about F# functions: how they’re much more powerful than the simple methods that you’re used to, and how you can often use simple functions instead of classes. And, as if that’s not enough, you’ll also learn how to construct larger applications through namespacing and modules.

There’ll be more and more F# code in the coming lessons, so make sure you have an open copy of Visual Studio at the ready with a blank .fsx file so that you can code as you go!