O'Reilly logo

Professional F# 2.0 by Richard Minerich, Talbott Crowell, Aaron C. Erickson, Ted Neward

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Chapter 13. Functions

WHAT'S IN THIS CHAPTER?

  • Reasoning about Functions

  • Understanding Type Restriction

  • Using First Class Functions

  • Partially Applying Functions

The way you think about functions is one of the things that most strongly differentiates F# from the other .NET languages. This doesn't come down to how functions are represented under the hood. Instead, it has more to do with the way functions are used conceptually.

When programming in F#'s functional style, functions are thought of as just another data type much like any object. They are frequently both passed into and returned from other functions. They also often have data stored inside of them through partial application or closures.

Although this can be done in other languages, it's not a frequently used feature and can take some getting used to. However, in time you will see that by leveraging these functional features more often, you can bring much to the table in terms of code succinctness and clarity. Indeed, much of F#'s power comes from this style of avoiding objects and focusing on functions.

TRADITIONAL FUNCTION CALLS

Traditionally, in mainstream imperative languages like C, C++, and C#, we treat functions as something completely different than the data that flows through our programs. They take a set of data, do some work on or with that data, and, most likely, change the state of our program in some way. They are like the channels through which the execution of our program flows, changing various data states along ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required