Search and Find
Service
Title Page
1
Copyright Page
2
Contents at a Glance
4
Table of Contents
5
Foreword
12
About the Author
14
About the Technical Reviewer
15
Acknowledgments
16
Preface
17
Chapter 1 Introduction
18
What Is Functional Programming?
18
Why Is Functional Programming Important?
19
What Is F#?
19
Who Is Using F#?
20
Who Is This Book For?
21
What’s Next?
21
Chapter 2 How to, Obtain, Install, and Use F#
23
Obtaining F#
23
Installing F# on Windows with Visual Studio 2008
24
Installing F# on Linux
24
Using F# in Different Ways
26
Visual Studio
26
SharpDevelop
27
F# Interactive Command-Line
28
The Examples in this Book
29
Summary
30
Chapter 3 Functional Programming
31
Literals
31
Functions
33
Identifiers and let Bindings
34
Identifier Names
35
Scope
36
Capturing Identifiers
40
The use Binding
41
Recursion
42
Operators
43
Function Application
44
Partial Application of Functions
46
Pattern Matching
47
Control Flow
51
Lists
52
Pattern Matching Against Lists
54
List Comprehensions
56
Types and Type Inference
59
Defining Types
61
Tuple and Record Types
61
Union or Sum Types
65
Type Definitions with Type Parameters
67
Recursive Type Definitions
69
Active Patterns
70
Complete Active Patterns
70
Incomplete Active Patterns
71
Units of Measure
73
Exceptions and Exception Handling
74
Lazy Evaluation
76
Summary
79
Chapter 4 Imperative Programming
80
The unit Type
80
The mutable Keyword
82
Defining Mutable Record Types
84
The ref Type
86
Arrays
88
Array Comprehensions
91
Control Flow
92
Calling Static Methods and Properties from .NET Libraries
95
Using Objects and Instance Members from .NET Libraries
97
Using Indexers from .NET Libraries
99
Working with Events from .NET Libraries
100
Pattern Matching over .NET Types
103
The |> Operator
105
Summary
107
Chapter 5 Object-Oriented Programming
108
Records As Objects
109
F# Types with Members
112
Object Expressions
115
Defining Classes
120
Optional Parameters
123
Defining Interfaces
124
Implementing Interfaces
125
Classes and Inheritance
127
Methods and Inheritance
128
Accessing the Base Class
129
Properties and Indexers
130
Overriding Methods from Non-F# Libraries
133
Abstract Classes
133
Classes and Static Methods
134
Classes with Explicit Fields and Constructors
135
Casting
136
Type Tests
138
Type Annotations for Subtyping
138
Defining Delegates
140
Structs
141
Enums
141
Summary
142
Chapter 6 Organizing, Annotating, and Quoting Code
143
Modules
143
Namespaces
145
Opening Namespaces and Modules
146
Giving Modules Aliases
149
Signature Files
149
Private and Internal let Bindings and Members
150
Module Scope
151
Module Execution
152
Optional Compilation
154
Comments
156
Doc Comments
156
Comments for Cross Compilation
158
Custom Attributes
159
Quoted Code
161
Summary
165
Chapter 7 The F# Libraries
166
The Native F# Library FSharp.Core.dll
166
The Microsoft.FSharp.Core.Operators Module
167
Arithmetic Operators
167
Floating-Point Arithmetic Functions
168
Tuple Functions
170
The Conversion Functions
170
The Logical Or and And Operators
171
The Microsoft.FSharp.Reflection Module
171
Reflection Over Types
171
Reflection Over Values
172
The Microsoft.FSharp.Collections.Seq Module
173
The map and iter Functions
174
The concat Function
175
The fold Function
175
The exists and forall Functions
176
The filter, find, and tryFind Functions
176
The choose Function
177
The init and initInfinite Functions
178
The unfold Function
179
The generate Function
180
The cast Function
181
The Microsoft.FSharp.Text.Printf Module
182
The Microsoft.FSharp.Control.Event Module
185
Creating and Handling Events
185
The filter Function
186
The partition Function
186
The map Function
187
The Power Pack Library FSharp.PowerPack.dll
187
The Microsoft.FSharp.Math Namespace
188
Summary
191
Chapter 8 User Interfaces
192
Introducing WinForms
192
Drawing WinForms
193
Working with Controls in WinForms
201
Using the Visual Studio Form Designer’s Forms in F#
206
Working with WinForms Events and the Event Module
209
Creating New Forms Classes
213
Introducing Windows Presentation Foundation
215
Introducing Windows Presentation Foundation 3D
217
Introducing GTK#
228
Introducing ASP.NET
230
Creating an IHttpHandler
231
Working with ASP.NET Web Forms
234
Summary
238
Chapter 9 Data Access
239
The System.Configuration Namespace
239
The System.IO Namespace
242
Using Sequences with System.IO
244
The System.Xml Namespace
246
ADO.NET
249
Data Binding
255
Data Binding and the DataGridView Control
257
ADO.NET Extensions
261
Introducing LINQ
266
Using LINQ to XML
267
Summary
270
Chapter 10 Parallel Programming
271
Threads, Memory, Locking and Blocking
272
Reactive Programming
275
Data Parallelism
281
Asynchronous Programming
288
Message Passing
292
Summary
301
Chapter 11 Distributed Applications
302
Networking Overview
302
Using TCP/IP Sockets
304
Using HTTP
314
Using HTTP with Google Spreadsheets
316
Using HTTP Posts
319
Using HTTP Asynchronously
320
Creating Web Services
323
Windows Communication Foundation
328
Hosting WCF Services
332
Summary
337
Chapter 12 Language-Oriented Programming
338
What Is Language-Oriented Programming?
338
Data Structures as Little Languages
338
A Data Structure–Based Language Implementation
340
Metaprogramming with Quotations
347
Implementing a Compiler and an Interpreter for an Arithmetic-Language
349
The Abstract Syntax Tree
350
Interpreting the AST
350
Compiling the AST
352
Compilation vs. Interpretation
356
Summary
360
Chapter 13 Parsing Text
361
Parsing CSV Format
361
Language Definition for the Other Examples
364
Using fslex.exe and fsyacc.exe
364
Tokenizing the Text: Fslex
365
Generating a Parser: Fsyacc
367
Using the Parser
369
FParsec Library
371
Summary
379
Chapter 14 Compatibility and Advanced Interoperation
380
Calling F# Libraries from C#
380
Returning Tuples
381
Exposing Functions That Take Functions As Parameters
383
Using Union Types
385
Using F# Lists
389
Defining Types in a Namespace
390
Defining Classes and Interfaces
392
Calling Using COM Objects
394
Using COM Style APIs
396
Using P/Invoke
397
Using Inline IL
400
Using F# from Native Code via COM
401
Hosting the CLR
404
Summary
406
Index
407
All prices incl. VAT