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:

let myInt = 42
let myFloat = 3.14
let myString = "hello functional programming" 
let myFunction = fun number -> number * number

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.

Understanding function signatures in F#

 
 
 

Creating mutable types: mutable and ref

 
 
 
 

Functions as first-class types

 

Composition: pipe and composition operators

 
 
 
 

Delegates

 
 
 

Comments

 
 

Open statements

 
 
 
 

Basic data types

 
 
 

Special string definition

 
 

Tuple

 
 
 

Record types

 
 
 

Discriminated unions

 
 
 
 

Pattern matching

 
 
 
 

Active patterns

 
 

Collections

 
 
 
 

Arrays

 
 

Sequences (seq)

 

Lists

 
 
 
 

Sets

 
 

Maps

 
 

Loops

 
 
 

Classes and inheritance

 
 
 

Abstract classes and inheritance

 

Interfaces

 

Object expressions

 
 
 
 

Casting

 

Units of measure

 
 
 

Event module API reference

 
 
 
 

Learn more

 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage