Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
The Book of F#: Breaking Free with Managed Functional Programming
About the Author
About the Technical Reviewer
Foreword
Preface
Acknowledgments
Introduction
Whom Is This Book For?
How Is This Book Organized?
Additional Resources
1. Meet F#
F# in Visual Studio
Project Templates
Project Organization
Significance of Whitespace
Grouping Constructs
Namespaces
Modules
Expressions Are Everywhere
Application Entry Point
Implicit Return Values
Your First F# Program
Summary
2. F# Interactive
Running F# Interactive
F# Interactive Output
The it Identifier
Playing in the Sandbox
#help
#quit
#load
#r
#I
#time
Scripting
F# Interactive Options
--load
--use
--reference
--lib
--define
--exec
--
--quiet
--optimize
--tailcalls
Summary
3. Fundamentals
Immutability and Side Effects
Functional Purity
Bindings
let Bindings
Literals
Mutable Bindings
Reference Cells
use Bindings
using Function
Replicating the using Function in C#
do Bindings
Identifier Naming
Core Data Types
Boolean Values and Operators
Numeric Types
Numeric Operators
Numeric Conversion Functions
Characters
Strings
String Literals
Verbatim Strings
Triple-Quoted Strings
String Concatenation
Type Inference
Nullability
Options
Unit Type
Enumerations
Flags Enumerations
Reconstructing Enumeration Values
Flow Control
Looping
while Loops
for Loops
Branching
Generics
Automatic Generalization
Explicit Generalization
Flexible Types
Wildcard Pattern
Statically Resolved Type Parameters
When Things Go Wrong
Handling Exceptions
try. . .with Expressions
try. . .finally Expressions
Raising Exceptions
Custom Exceptions
String Formatting
Type Abbreviations
Comments
End-of-Line Comments
Block Comments
XML Documentation
Summary
4. Staying Objective
Classes
Constructors
Primary Constructors
Additional Constructors
Self-Identifiers
Fields
let Bindings
Explicit Fields
Properties
Explicit Properties
Implicit Properties
Indexed Properties
Setting at Initialization
Methods
Instance Methods
Method Accessibility
Named Arguments
Overloaded Methods
Optional Parameters
Slice Expressions
Events
Basic Event Handling
Observing Events
Custom Events
Structures
Inheritance
Casting
Upcasting
Downcasting
Overriding Members
Abstract Classes
Abstract Members
Abstract Properties
Abstract Methods
Virtual Members
Sealed Classes
Static Members
Static Initializers
Static Fields
Static Properties
Static Methods
Mutually Recursive Types
Interfaces
Implementing Interfaces
Defining Interfaces
Custom Operators
Prefix Operators
Infix Operators
New Operators
Global Operators
Object Expressions
Type Extensions
Summary
5. Let’s Get Functional
What Is Functional Programming?
Programming with Functions
Functions as Data
Interoperability Considerations
Currying
Partial Application
Pipelining
Forward Pipelining
Backward Pipelining
Noncurried Functions
Function Composition
Recursive Functions
Tail-Call Recursion
Mutually Recursive Functions
Lambda Expressions
Closures
Functional Types
Tuples
Extracting Values
Equality Semantics
Syntactic Tuples
Out Parameters
Record Types
Defining Record Types
Creating Records
Avoiding Naming Conflicts
Copying Records
Mutability
Additional Members
Discriminated Unions
Defining Discriminated Unions
Simple Object Hierarchies
Tree Structures
Replacing Type Abbreviations
Additional Members
Lazy Evaluation
Summary
6. Going to Collections
Sequences
Creating Sequences
Sequence Expressions
Range Expressions
Empty Sequences
Initializing a Sequence
Working with Sequences
Finding Sequence Length
Iterating over Sequences
Transforming Sequences
Sorting Sequences
Filtering Sequences
Aggregating Sequences
Arrays
Creating Arrays
Array Expressions
Empty Arrays
Initializing Arrays
Working with Arrays
Accessing Elements
Copying Arrays
Sorting Arrays
Multidimensional Arrays
Jagged Arrays
Lists
Creating Lists
Working with Lists
Accessing Elements
Combining Lists
Sets
Creating Sets
Working with Sets
Unions
Intersections
Differences
Subsets and Supersets
Maps
Creating Maps
Working with Maps
Finding Values
Finding Keys
Converting Between Collection Types
Summary
7. Patterns, Patterns, Everywhere
Match Expressions
Guard Clauses
Pattern-Matching Functions
Exhaustive Matching
Variable Patterns
The Wildcard Pattern
Matching Constant Values
Identifier Patterns
Matching Union Cases
Matching Literals
Matching Nulls
Matching Tuples
Matching Records
Matching Collections
Array Patterns
List Patterns
Cons Patterns
Matching by Type
Type-Annotated Patterns
Dynamic Type-Test Patterns
As Patterns
Combining Patterns with AND
Combining Patterns with OR
Parentheses in Patterns
Active Patterns
Partial Active Patterns
Parameterized Active Patterns
Summary
8. Measuring Up
Defining Measures
Measure Formulas
Applying Measures
Stripping Measures
Enforcing Measures
Ranges
Converting Between Measures
Static Conversion Factors
Static Conversion Functions
Generic Measures
Custom Measure-Aware Types
Summary
9. Can I Quote You on that?
Comparing Expression Trees and Quoted Expressions
Composing Quoted Expressions
Quoted Literals
.NET Reflection
Manual Composition
Splicing Quoted Expressions
Decomposing Quoted Expressions
Parsing Quoted Expressions
Substituting Reflection
Summary
10. Show Me the Data
Query Expressions
Basic Querying
Filtering Data
Predicate-Based Filters
Distinct-Item Filters
Accessing Individual Items
Getting the First or Last Item
Getting an Arbitrary Item
Sorting Results
Sorting in Ascending Order
Sorting in Descending Order
Sorting by Multiple Values
Grouping
Paginating
Aggregating Data
Detecting Items
Joining Multiple Data Sources
Extending Query Expressions
Example: ExactlyOneWhen
Example: AverageByNotNull
Type Providers
Available Type Providers
Using Type Providers
Example: Accessing an OData Service
Example: Parsing a String with RegexProvider
Summary
11. Asynchronous and Parallel Programming
Task Parallel Library
Potential Parallelism
Data Parallelism
Locking and Lock Avoidance
Short-Circuiting Parallel Loops
Cancelling Parallel Loops
Task Parallelism
Creating and Starting Tasks
Returning Values from Tasks
Waiting for Task Completion
Continuations
Cancelling Tasks
Exception Handling
Asynchronous workflows
Creating and Starting Asynchronous Workflows
Cancelling Asynchronous Workflows
Exception Handling
Asynchronous Workflows and the Task Parallel Library
Agent-Based Programming
Getting Started
Scanning for Messages
Replying to Messages
Example: Agent-Based Calculator
Summary
12. Computation Expressions
Anatomy of a Computation Expression
Example: FizzBuzz
Example: Building Strings
Summary
Index
About the Author
Copyright
← Prev
Back
Next →
← Prev
Back
Next →