Learn F#
Isaac Abraham
  • MEAP began September 2016
  • Publication in Spring 2017 (estimated)
  • ISBN 9781617293993
  • 400 pages (estimated)
  • printed in black & white

F# is a mature, open-source functional-first language that’s rapidly growing in popularity both inside and outside the .NET ecosystem. And while F# runs on the .NET framework and supports OO features, its functional nature is what’s driving interest. F# leads to quicker development time and a lower total cost of ownership. Its powerful feature set allows developers to more succinctly express their intent, and encourages best practices – leading to higher quality deliverables in less time. Developers find working in F# more enjoyable and rewarding; their managers appreciate the improved quality and speed of deliverables!

Learn F# is a practical guide for experienced C# and .NET developers that teaches the F# language, tools, techniques, and practices that can be applied in common scenarios. You’ll start with F# language basics and best development practices. You’ll also learn the core set of FP techniques in F#, and why to use them. Then you’ll discover how to write idiomatic F# code on the .NET framework in Visual Studio, and what tools to use to give you the best experience within VS. The second part of the book shows you how to apply F# in larger, real world scenarios, things like interop to C# /VB projects, SQL database access, web programming, and unit testing. By the end of the book, you’ll be able to use F# in your day-to-day development, and know how and where to deepen your knowledge.

Table of Contents detailed table of contents

Welcome to Learn F#!

0.1 What is F# - and why does it matter?

0.1.1 What is F#?

0.1.2 F# alongside other programming languages

0.1.3 Why F#?

0.1.4 Working with a smarter compiler

0.1.5 What#s the catch?

0.2 What this book covers

0.2.1 Focusing on F# fundamentals

0.2.2 Real world libraries

0.2.3 Book structure

0.3 F# and .NET

0.3.1 F#s place within .NET

0.4 F# and Open Source

0.4.1 The F# community

0.4.2 Coding in the open source world

0.4.3 A real-world example of open source contributions

0.5 Summary

Unit 1: F# and Visual Studio

Lesson 1 The Visual Studio Experience

1.1 Installing VS2015 with F#

1.2 Configuring Visual Studio for F#

1.2.1 Visual F# Tools configuration

1.2.2 Configuring the F# Editor

1.3 Getting the best out of VS 2015 and F#

1.3.1 Installing Visual F# Power Tools

1.3.2 Configuring F# Syntax Highlighting

1.4 Summary

Lesson 2 Creating your first F# program

2.1 F# Project Types

2.2 Debugging applications in F#

2.3 Writing your first F# snippet

2.4 Summary

Lesson 3 The REPL - Changing how we develop

3.1 Priming exercise: Thinking about your development process

3.1.1 Application-based Development

3.1.2 Console Test Rigs

3.1.3 Automated unit tests

3.2 Enter the REPL

3.3 The F# REPL

3.3.1 State in FSI

3.4 F# Scripts in Visual Studio

3.5 Working with Scripts and FSI

3.5.1 Working with functions in scripts

3.6 Summary

Unit 2: Hello F#

Lesson 4 Saying a little, doing a lot

4.1 Priming Exercise: Thinking about syntax as the "character" of a language

4.2 Binding values in F#

4.2.1 Let isn’t var!

4.3 Scoping

4.3.1 Nested scopes

4.3.2 Nested functions

4.4 Cyclical Dependencies in F#

4.5 Summary

Lesson 5 Trusting the Compiler

5.1 A refresher on type inference today in C# and VB

5.2 Imagining a more powerful Type Inference system

5.3 Type Inference with F#

5.4 Limitations of type inference

5.4.1 Working with the BCL

5.4.2 Classes and Overloaded methods

5.4.3 Cyclical Dependencies

5.5 Type Inferred Generics

5.6 Following the breadcrumbs

5.7 Summary

Lesson 6 Working with immutable data

6.1 Thinking about the mutable world in software development

6.1.1 The unrepeatable bug

6.1.2 Multithreading pitfalls

6.1.3 Accidentally sharing state

6.1.4 Testing hidden state

6.2 Being explicit about mutation

6.3 Working with mutable objects

6.4 Modelling state

6.4.1 Working with mutable data

6.4.2 Working with immutable data

6.4.3 Other benefits of immutable data

6.5 Summary

Lesson 7 Expressions and Statements

7.1 What are expressions and statements?

7.2 Priming exercise: How statements can make life difficult

7.3 Making life better through Expressions

7.4 Expressions in F#

7.5 Composability

7.6 Introducing Unit

7.7 Trusting the compiler again

7.8 Escape hatches

7.9 Forcing statement-based evaluation

7.10 Summary

Unit 3: Types and Functions

Lesson 8 Shaping data with Tuples

8.1 Priming exercise - returning data from a method

8.2 Tuples in F#

8.2.1 When should I use Tuples?

8.3 More complex Tuples

8.3.1 Tuple Type Signatures

8.3.2 Nested Tuples

8.3.3 Wildcards

8.4 Type Inference with Tuples

8.5 Tuple best practices

8.5.1 Tuples and the BCL

8.5.2 When not to use Tuples

8.6 Summary

Lesson 9 Shaping data with Records

9.1 Priming exercise - creating an immutable type in C#

9.2 POCOs done right - Records in F#

9.3 Creating Records

9.4 Type Inference with Records

9.5 Working with immutable Records

9.6 Equality Checking

9.7 Tips and tricks with Records

9.7.1 Refactorings

9.7.2 Shadowing

9.8 When to use records

9.9 Summary

Lesson 10 Building composable functions

10.1 Comparing methods and functions

10.2 Partial function application

10.3 Using Curried Functions

10.3.1 Constraining functions

10.3.2 Pipelines

10.3.3 Composing functions together

10.4 Summary

Lesson 11 Organising code without classes

11.1 Organising code elements in F#

11.2 Namespaces in F#

11.3 Modules in F#

11.3.1 Visualising namespaces and modules

11.3.2 Opening modules

11.4 Namespaces vs Modules

11.5 Moving from scripts to applications

11.6 Tips for working with Modules and Namespaces

11.6.1 Access Modifiers

11.6.2 The global namespace

11.6.3 Automatic namespacing

11.6.4 Automatic opening of modules

11.6.5 Scripts

11.7 Summary

Lesson 12 Achieving code reuse in F#

12.1 Priming Exercise: How do you reuse code today?

12.2 Reuse in the world of LINQ

12.3 Implementing higher order functions in F#

12.4 When to pass functions as arguments

12.5 Dependencies as functions

12.6 Summary

Capstone Exercise 1: Bank Accounts

CE1.1 Defining the problem

CE1.2 Some advice before you start…​

CE1.3 Getting started

CE1.4 Creating a domain

CE1.5 Creating behaviours

CE1.6 Abstraction and reuse through higher order functions

CE1.6.1 Adapting code with higher order functions

CE1.7 Writing a console application

CE1.7.1 Writing the Program

CE1.7.2 Managing the account state

CE1.8 Referencing files from scripts

CE1.9 Summary

Unit 4: Collections in F#

Lesson 13 Working with collections in F#

13.1 Priming Exercise: Working with collections today

13.1.1 In place collection modifications

13.1.2 The collection modules

13.1.3 Transformation pipelines

13.1.4 Debugging pipelines

13.1.5 Compose, compose, compose

13.2 Working with sequences

13.3 Using .NET arrays

13.4 Immutable Lists

13.5 Summary

Lesson 14 Useful collection functions

14.1 Mapping Functions

14.1.1 Map

14.1.2 Iter

14.1.3 Collect

14.1.4 Pairwise

14.2 Grouping functions

14.2.1 GroupBy

14.2.2 CountBy

14.2.3 Partition

14.3 Aggregate functions

14.4 Miscellaneous functions

14.5 Converting between collections

14.6 Summary

Lesson 15 Maps, Dictionaries and Sets

15.1 Dictionaries

15.1.1 Mutable dictionaries in F#

15.1.2 Immutable Dictionaries

15.2 The F# Map

15.2.1 Useful Map functions

15.3 Sets

15.4 Summary

Lesson 16 Folding our way to success

16.1 Understanding aggregations and accumulators

16.1.1 Creating our first Aggregation function

16.2 Saying hello to fold

16.2.1 Making fold more readable

16.3 Folding instead of while loops

16.4 Composing functions with fold

16.4.1 Composing rules manually

16.4.2 Folding functions together

16.5 Summary

Unit 5: The Pit of Success with the F# Type System

Lesson 17 Program Flow in F#

17.1 A tour around loops in F#

17.1.1 For loops

17.1.2 While loops

17.1.3 Comprehensions

17.2 Branching logic in F#

17.2.1 Priming Exercise - Customer Credit Limits

17.3 Say hello to pattern matching

17.3.1 Exhaustive checking

17.3.2 Guards

17.3.3 Nested matches

17.4 Flexible pattern matching

17.4.1 Collections

17.4.2 Records

17.5 To match or not to match

17.6 Summary

Lesson 18 Modelling Relationships in F#

18.1 Modelling Relationships

18.1.1 Composition in F#

18.1.2 Modelling a type hierarchy

18.2 Discriminated Unions in F#

18.2.1 Creating instances of DUs

18.2.2 Accessing an instance of a DU

18.3 Tips for working with Discriminated Unions

18.3.1 Nested DUs

18.3.2 Shared fields

18.3.3 Printing out DUs

18.4 Comparing OO hierarchies and Discriminated Unions

18.5 Creating Enums

18.6 Summary

Lesson 19 Fixing the billion-dollar mistake

19.1 Working with missing values

19.2 The rise of the billion-dollar mistake

19.3 Nullable Types in .NET

19.4 Improving matters with the F# Type System

19.4.1 Mandatory data in F#

19.4.2 The Option Type

19.5 The Option module

19.5.1 Mapping

19.5.2 Binding

19.5.3 Filtering

19.5.4 Other Option functions

19.6 Collections and Options

19.6.1 Option.toList

19.6.2 List.choose

19.6.3 "Try" functions

19.7 Summary

Lesson 20 Business Rules as Code

20.1 Validating business rules

20.2 Specific types in F#

20.2.1 Mixing values of the same type

20.2.2 Single Case Discriminated Unions

20.3 Handling different contact methods

20.3.1 Combining discriminated unions

20.4 Encoding business rules with marker types

20.4.1 When and when not to use marker types

20.5 Results vs Exceptions

20.5.1 Safe functions with Results

20.6 Summary

Capstone Exercise 2

Unit 6: Living on the .NET platform

Lesson 21 Consuming C# from F#

Lesson 22 Exposing F# Types and Functions to C#

Lesson 23 Consuming Nuget Packages from F#

Lesson 24 Creating WPF applications with F#

Capstone Exercise 3

Unit 7: Working with Data

Lesson 25 What are Type Providers?

Lesson 26 Working with common data formats [ JSON, CSV, XML etc. ]

Lesson 27 Building Schemas from Live Data

Lesson 28 Working with SQL

Lesson 29 Creating Type Provider-backed APIs

Lesson 30 Using type providers in real world applications

Capstone Exercise 4

Unit 8: Web Programming

Lesson 31 Asychronous Workflows

Lesson 32 Exposing data over HTTP with Web API

Lesson 33 Introducing Suave

Lesson 34 Consuming HTTP data

Capstone Exercise 5

Unit 9: Unit Test

Lesson 35 Basic unit testing [ NUnit , XUnit etc.]

Lesson 36 Testing DSLs [ FSUnit etc. ]

Lesson 37 Property Based Testing

Lesson 38 Testing web applications

Unit 10: Where next?

Lesson 39 F# in my organisation?

Lesson 40 Must-have F# libraries

Lesson 41 Must-visit F# resources

What's inside

  • Organized in short lessons of a few pages each
  • Quick Check questions to make sure you're on track
  • Practice as you learn with Try This exercises
  • Using the F# REPL to rapidly prototype and implement applications
  • Writing bug-free code without the need for unit tests
  • Solving complex problems using simple code
  • Creating REST-style web application
  • Working with JSON, CSV, XML, and HTML data
  • Integrating F# code with existing C# and VB .NET systems

About the reader

For intermediate C# and Visual Basic .NET developers who have heard about F# and functional programming and want to understand the benefits and use it as a part of their existing toolbox without having to throw away existing code.

About the author

Isaac Abraham is an F# MVP and a .NET developer since .NET 1.0 with an interest in cloud computing and distributed data problems. He lives in both the UK and Germany, and is the director of Compositional IT.


Manning Early Access Program (MEAP) Read chapters as they are written, get the finished eBook as soon as it’s ready, and receive the pBook long before it's in bookstores.
Buy
  • MEAP combo $44.99 pBook + eBook
  • MEAP eBook $35.99 pdf + ePub + kindle

FREE domestic shipping on three or more pBooks