Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
Programming F# 3.0
Preface
Introducing F#
Who This Book Is For
What You Need to Get Going
How the Book Is Organized
Part I
Part II
Part III
Part IV
Conventions Used in This Book
Using Code Examples
Safari® Books Online
I’d Like to Hear from You
Acknowledgments
I. Multiparadigm Programming
1. Introduction to F#
Getting to Know F#
Visual Studio 11
Your Second F# Program
Values
Whitespace Matters
.NET Interop
Comments
F# Interactive
Managing F# Source Files
2. Fundamentals
Primitive Types
Numeric Primitives
Arithmetic
Conversion Routines
BigInteger
Bitwise Operations
Characters
Strings
Boolean Values
Comparison and Equality
Functions
Type Inference
Generic Functions
Scope
Control Flow
Core Types
Unit
Tuple
Lists
List ranges
List comprehensions
List module functions
Aggregate Operators
List.map
List.fold
Folding right-to-left
List.iter
Option
Printf
Organizing F# Code
Modules
Creating modules
Nested modules
Namespaces
Program Startup
3. Functional Programming
Understanding Functions
Immutability
Function Values
Partial function application
Functions returning functions
Recursive Functions
Mutual recursion
Symbolic Operators
Function Composition
Pipe-forward operator
Forward composition operator
Pipe-backward operator
Backward composition operator
Pattern Matching
Match Failure
Named Patterns
Matching Literals
when Guards
Grouping Patterns
Matching the Structure of Data
Tuples
Lists
Options
Outside of Match Expressions
let bindings
Function parameters
Wildcard patterns
Alternate Lambda Syntax
Discriminated Unions
Using Discriminated Unions for Tree Structures
Pattern Matching
Methods and Properties
Records
Cloning Records
Pattern Matching
Type Inference
Methods and Properties
Lazy Evaluation
Lazy Types
Sequences
Sequence Expressions
Seq Module Functions
Seq.take
Seq.unfold
Aggregate Operators
Seq.iter
Seq.map
Seq.fold
Queries
Query Expressions
Query Operators
Selection operators
Sorting operators
4. Imperative Programming
Understanding Memory in .NET
Value Types Versus Reference Types
Default Values
Reference Type Aliasing
Changing Values
Reference Cells
Mutable Records
Units of Measure
Defining Units of Measure
Converting Between Units of Measure
Generic Units of Measure
Arrays
Indexing an Array
Array Slices
Creating Arrays
Pattern Matching
Array Equality
Array Module Functions
partition
tryFind and tryFindIndex
Aggregate operators
Multidimensional Arrays
Rectangular arrays
Jagged arrays
Mutable Collection Types
List<'T>
Dictionary<'K,'V>
HashSet<'T>
Looping Constructs
While Loops
For Loops
Simple for loops
Enumerable for loop
Exceptions
Handling Exceptions
Reraising Exceptions
Defining Exceptions
5. Object-Oriented Programming
Programming with Objects
The Benefits of OOP
Where OOP Breaks Down
Understanding System.Object
Common Methods
ToString
GetHashCode
Equals
GetType
Object Equality
Generated Equality
Understanding Classes
Explicit Construction
Implicit Class Construction
Generic Classes
The Self Identifier
Methods and Properties
Properties
Auto-properties
Setting Properties in the Constructor
Methods
Static Methods, Properties, and Fields
Static fields
Method Overloading
Accessibility Modifiers
Accessibility modifiers on module values
F# signature files
Inheritance
Method Overriding
Categories of Classes
Abstract classes
Sealed classes
Casting
Static upcast
Dynamic cast
Pattern matching against types
6. .NET Programming
The .NET Platform
The CLI
Garbage Collection
Interfaces
Using Interfaces
Defining Interfaces
Object Expressions
Object Expressions for Interfaces
Object Expressions for Derived Classes
Extension Methods
Extending Modules
Enumerations
Creating Enumerations
Conversion
When to Use an Enum Versus a Discriminated Union
Structs
Creating Structs
Restrictions
When to Use a Struct Versus a Record
II. Programming F#
7. Applied Functional Programming
Active Patterns
Single-Case Active Patterns
Partial Active Patterns
Parameterized Active Patterns
Multicase Active Patterns
Using Active Patterns
Combining active patterns
Nesting active patterns
Using Modules
Converting Modules to Classes
Intentional Shadowing
Controlling Module Usage
Mastering Lists
List Operations
Cons
Append
Using Lists
Tail Recursion
Understanding the Stack
Introducing Tail Recursion
Tail-Recursive Patterns
Accumulator pattern
Continuations
Programming with Functions
Partial Function Application
Passing functions as parameters
Eliminating Redundant Code
Closures
Functional Patterns
Memoization
Memoizing recursive functions
Mutable Function Values
Lazy Programming
Reducing memory usage
Abstracting data access
Functional Data Structures
Functional Set
Functional Map
8. Applied Object-Oriented Programming
Operators
Operator Overloading
Indexers
Adding Slices
Generic Type Constraints
Delegates and Events
Defining Delegates
Combining Delegates
Events
Creating Events
Delegates for events
Creating and raising the event
Subscribing to events
The Event<_,_> Class
The Observable Module
Observable.add
Observable.merge
Observable.map
Creating .NET Events
9. Asynchronous and Parallel Programming
Working with Threads
Spawning Threads
Thread.Sleep
Thread.Abort
The .NET Thread Pool
Sharing Data
Race conditions
Deadlocks
Asynchronous Programming
Asynchronous Workflows
The Async Library
Starting async tasks
Exceptions
Cancellation
Async Operations
Custom Async Primitives
Limitations
Parallel Programming
Parallel.For
The Array.Parallel Module
Task Parallel Library
Primitives
Cancellation
Exceptions
Concurrent Data Structures
Concurrent queue
Concurrent dictionary
Concurrent bag
10. Scripting
F# Script Files
Directives
General Directives
__SOURCE_DIRECTORY__
__SOURCE_FILE__
F# Script-Specific Directives
#r
#I
#load
F# Script Recipes
Colorful Output
Producing Sound
Walking a Directory Structure
Starting Processes Easily
Automating Microsoft Office
11. Data Processing
Indexing
The Index Data Structure
Token posting lists
MapReduce Processing
Benefits
Cloud hosts
Search Index Mapper
Search Index Reducer
Querying
Lex and Yacc
Parsing
Lexing
Query Processing
Token posting lists
Keyword queries
Exact phrase queries
Logical operators
Putting them together
Next steps
III. Extending the F# Language
12. Reflection
Attributes
Applying Attributes
Attribute targets
Applying multiple attributes
Defining New Attributes
Type Reflection
Accessing Types
Accessing generic types
Inspecting methods
Inspecting attributes
Reflecting on F# Types
Tuples
Discriminated unions
Records
Dynamic Instantiation
Instantiating Types
Instantiating F# Types
Dynamic Invocation
The Question Mark Operators
Using Reflection
Declarative Programming
Plug-in Architecture
Plug-in interfaces
Loading assemblies
Loading plug-ins
13. Computation Expressions
Toward Computation Expressions
Computation Expression Builders
Custom Computation Expression Builders
Asynchronous Workflows
The Rounding Workflow
The State Workflow
Building up the computation
Implementation
14. Quotations
Quotation Basics
Decomposing Quotations
Literal values
Function calls
Function values
Quoting Method Bodies
Decomposing Arbitrary Code
Application: Deferring Computation to Other Platforms
Generating Quotation Expressions
Expression Holes
Evaluating Quotations
Application: Generating Derivatives
15. Type Providers
Typed Data Versus Typed Languages
Wrapper Assemblies
F# Type Providers
Advantage over shim libraries
Advantage over IDEs
Type Providers
SQL Data Type Providers
LINQ to SQL
DbmlFile
Entity Framework
Web Service Type Providers
The WsdlService Provider
The ODataService Provider
Custom Type Providers
IV. Appendixes
A. Overview of .NET Libraries
Visualization
Windows Forms
Windows Presentation Foundation
XAML, the eXtensible Application Markup Language
Binding
Data Processing
Regular Expressions
Metacharacters
String manipulation
Capture groups
Working with XML
Writing XML
Reading XML
Storing Data
File I/O
Data Serialization
Deserialization
B. F# Interop
.NET Interop
Nullable Types
Linq.NullableOperators
C# Interoperating with F#
Discriminated unions
Function values
F# Interoperating with C#
Byref and out parameters
Dealing with null
Unmanaged Interop
Platform Invoke
COM Interop
Index
About the Author
Colophon
Copyright
← Prev
Back
Next →
← Prev
Back
Next →