Skip to main content
main-content
Top

About this book

Learn from F#'s inventor to become an expert in the latest version of this powerful programming language so you can seamlessly integrate functional, imperative, object-oriented, and query programming style flexibly and elegantly to solve any programming problem. Expert F# 4.0 will help you achieve unrivaled levels of programmer productivity and program clarity across multiple platforms including Windows, Linux, Android, OSX, and iOS as well as HTML5 and GPUs.

F# 4.0 is a mature, open source, cross-platform, functional-first programming language which empowers users and organizations to tackle complex computing problems with simple, maintainable, and robust code.

Expert F# 4.0 is:

A comprehensive guide to the latest version of F# by the inventor of the languageA treasury of F# techniques for practical problem-solvingAn in-depth case book of F# applications and F# 4.0 concepts, syntax, and features

Written by F#'s inventor and two major F# community members, Expert F# 4.0 is a comprehensive and in-depth guide to the language and its use. Designed to help others become experts, the book quickly yet carefully describes the paradigms supported by F# language, and then shows how to use F# elegantly for a practical web, data, parallel and analytical programming tasks.

The world's experts in F# show you how to program in F# the way they do!

Table of Contents

Frontmatter

Chapter 1. Introduction

Abstract
F# is an open-source, cross-platform, functional-first programming language that empowers all levels of programmers to write simple, robust code for a huge range of practical purposes. F# combines the succinctness, expressivity, efficiency, and robustness of functional programmingprogramming based on transformations of datawith the runtime support, libraries, interoperability, tools, and object models of modern programming frameworks. F# is the safe choice for modern programming, embracing both enterprise quality through tools for a wide range of editors and operating systems, and openness, allowing you to contribute to the language and its ecosystem.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 2. Your First F# Program: Getting Started with F#

Abstract
This chapter will cover simple interactive programming with F#. To begin, download and install F# from fsharp.org, if you don’t have it installed already. The sections that follow use F# Interactive (fsi.exe or fsharpi), a tool you can use to execute fragments of F# code interactively, and that is convenient for exploring the language. Along the way, you will see examples of the most important F# language constructs and many important libraries.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 3. Introducing Functional Programming

Abstract
F#’s effectiveness rests on the tried and tested foundation of functional programming. This chapter will cover the core building blocks of functional programming with F#, including simple types and function values, pattern matching, lists, and options. Chapters 4 through 6 will cover imperative programming, generics, and object-oriented programming, and Chapters 8, 9, and 10 will cover more advanced topics in functional programming with text, sequences, and structured and numeric data.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 4. Introducing Imperative Programming

Abstract
In Chapter 3, you saw some of the constructs that make up F# functional programming. At the core of the functional programming paradigm is “programming without side effects,” also called pure functional programming. In this chapter you will learn about programming with side effects, called imperative programming.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 5. Understanding Types in Functional Programming

Abstract
F# is a typed language, and F# programmers often use types in sophisticated ways. In this chapter, you will learn about the foundations of types, focusing on how they are defined and used in F# functional programming. You also will look closely at generics, and closely related to generics is the notion of subtyping. Generics and subtyping combine to allow you to write code that is generic over families of types. You will see how F# uses automatic generalization to automatically infer generic types for your code, and the chapter will cover some of the basic generic functions in the F# libraries, such as generic comparison, hashing, and binary serialization.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 6. Programming with Objects

Abstract
Chapters 2 through 5 dealt with the basic constructs of F# functional and imperative programming, and by now we trust you’re familiar with the foundational concepts and techniques of practical, small-scale F# programming. This chapter covers language constructs related to object programming.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 7. Encapsulating and Organizing Your Code

Abstract
Organizing code and making it available for people and programs to use is a key part of best using F#. In this book, you’ve already seen many of the constructs to help you do this: functions, objects, type definitions, modules, namespaces, and assemblies. In some cases, however, you’ve encountered these only peripherally when using the libraries that come with F#. This chapter will cover these constructs from the perspective of code organization and encapsulation.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 8. Working with Textual Data

Abstract
Chapters 2 and 3 introduced the F# type for strings. While F#’s specialty is in programming with structured data, unstructured textual data is exceptionally common in programming, both as a data format and as an internal representation in algorithms that work over documents and text. In this chapter, you will learn some of the techniques available for working with textual data in F# programs, including working with the XML and JSON semi-structured data formats, which are initially represented as text.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 9. Working with Sequences and Tree-Structured Data

Abstract
In the previous chapter, you learned to manipulate textual data, including how to convert text to structured data through parsing and back again through formatting. In this chapter, you will focus on F# programming techniques related to structured data.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 10. Numeric Programming and Char ting

Abstract
In Chapters 8 and 9, you learned constructs and techniques for programming with three important kinds of data in F#: textual data, sequences of data, and structured data. In this chapter, we will return to constructs and techniques for one of the most important kinds of data in programming systems: numeric data.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 11. Reactive, Asynchronous, and Parallel Programming

Abstract
So far in this book, you’ve seen functions and objects that process their inputs immediately using a single thread of execution in which the code runs to completion and produces useful results or state changes. In this chapter, you will turn your attention to concurrent, parallel, asynchronous, and programs. These represent substantially different approaches to programming from those you’ve seen so far. Some reasons for turning to these techniques are the following:
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 12. Symbolic Programming with Structured Data

Abstract
Symbols are everywhere. Numbers are symbols that stand for quantities, and you can add, multiply, or take square roots of numbers that are so small or large that it’s hard to imagine the quantity they represent. You can solve equations, multiply polynomials, approximate functions using series, and differentiate or integrate numerically or symbolically—these are just a few everyday examples of using symbols in mathematics.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 13. Integrating External Data and Services

Abstract
One of the major trends in modern computing is the “data deluge,” meaning the rapid rise in digital information available for analysis, especially through reliable networked services and large-scale data-storage systems. Some of this data may be collected by an individual or an organization, some may be acquired from data providers, and some may be gathered from free data sources.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 14. Building Smart Web Applications

Abstract
Delivering content and applications via web browsers is one of the most important aspects of modern software development. This chapter will examine how you can build web applications using F#. Some of the topics covered are the following:
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 15. Visualization and Graphical User Interfaces

Abstract
GUI applications revolve around events, and F# provides a natural way to process events with functions. Graphical interfaces are often developed using visual editors, in particular to build GUIs by assembling controls. Applications, however, often need drawing capabilities for displaying and manipulating data, which requires custom programming to augment available controls. This chapter will discuss how to develop graphical applications with F# and why the functional traits of the language suit the event-driven programming paradigm typical of GUIs.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 16. Language-Oriented Programming

Abstract
Chapters 3 to 6 covered three well-known programming paradigms in F#: functional, imperative, and object programming. Throughout this book, however, you have in many ways been exploring what is essentially a fourth programming paradigm: language-oriented programming. In this chapter, you will focus on advanced aspects of language-oriented programming through language-integrated, domain-specific languages and meta-programming.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 17. Libraries and Interoperability

Abstract
Software integration and reuse is becoming one of the most relevant activities in software development. This chapter will discuss how F# programs can interoperate with the outside world by accessing code available from both .NET and other languages.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 18. Developing and Testing F# Code

Abstract
Successful programming must involve a healthy marriage of good code and good software engineering. Sometimes these overlap: functional programming is a good software-engineering technique. Among other benefits, anecdotal evidence indicates that functional programming frequently leads to a substantially reduced bug rate for good programmers. Programs built using functional techniques tend to be highly compositional, building correct programs out of correct building blocks. The functional programming style avoids or substantially reduces the use of side effects in the program, one property that makes programs more compositional and comprehensible.
Don Syme, Adam Granicz, Antonio Cisternino

Chapter 19. Designing F# Libraries

Abstract
This book deals with F#, a functional-first language situated in a broader context of software construction and engineering. As an expert F# programmer, you need more than knowledge of the F# language; you also need to wisely use a range of software-engineering tools and methodologies to build software that is truly valuable for the situation in which it’s deployed. The previous chapter touched on some important tools. This final chapter will look at some of the methodological issues related to F# library design, including the following:
Don Syme, Adam Granicz, Antonio Cisternino

Appendix. F# Brief Language Guide

Abstract
This appendix will describe the essential constructs of the F# language in a compact form. You can find a full guide to the F# language in the F# Language Specification on the F# website ( http://fsharp.org/specs/ ).
Don Syme, Adam Granicz, Antonio Cisternino

Backmatter

Additional information

Premium Partner

    Image Credits