B F# overview
This appendix explores the basic syntax of F#, which is an established general-purpose functional first language with object-oriented programming (OOP) support. In fact, F# embraces the .NET common language infrastructure (CLI) object model, which allows the declaration of interfaces, classes, and abstract classes. Furthermore, F# is a statically and strongly typed language, which means that the compiler can detect the data type of variables and functions at compile time. F#’s syntax is different from C-style languages, such as C#, because curly braces aren’t used to delimit blocks of code. Moreover, whitespace rather than commas and indentation is important to separate arguments and delimit the scope of a function body. In addition, F# is a cross-platform programming language that can run inside and outside the .NET ecosystem.
The let binding
In F#, let
is one of the most important keywords that binds an identifier to a value, which means giving a name to value (or, bind a value to a name). It’s defined as let <identifier> = <value>.
The let
bindings are immutable by default. Here are a few code examples:
As you can see from the last line, you can name a function by binding the identifier myFunction
to the lambda expression fun number -> number * number
.