Home Page Icon
Home Page
Table of Contents for
About the Technical Reviewer
Close
About the Technical Reviewer
by Antonio Cisternino, Adam Granicz, Don Syme
Expert F# 2.0
Copyright
Foreword
About the Authors
About the Technical Reviewer
Acknowledgments
1. Introduction
1.1. The Genesis of F#
1.2. About This Book
1.3. Who This Book Is For
2. Getting Started with F# and .NET
2.1. Creating Your First F# Program
2.1.1. Documenting Code Using XMLDocs
2.1.2. Using let
2.1.3. Understanding Types
2.1.4. Calling Functions
2.1.5. Lightweight Syntax
2.1.6. Understanding Scope
2.1.7. Using Data Structures
2.1.8. Using Properties and the Dot-Notation
2.1.9. Using Tuples
2.1.10. Using Imperative Code
2.2. Using .NET Libraries from F#
2.2.1. Using open to Access Namespaces and Modules
2.2.2. Using new and Setting Properties
2.2.3. Fetching a Web Page
2.3. Summary
3. Creating Your First F# Program—Introducing Functional Programming
3.1. Getting Started with F# Arithmetic
3.1.1. Basic Literals
3.1.2. Arithmetic Operators
3.1.3. Bitwise Operations
3.1.4. Arithmetic Conversions
3.1.5. Arithmetic Comparisons
3.1.6. Overloaded Math Functions
3.2. Introducing Simple Strings
3.2.1. Working with String Literals and Primitives
3.2.2. Building Strings
3.3. Working with Lists and Options
3.3.1. Using F# Lists
3.3.2. Using F# Option Values
3.3.3. Using Option Values for Control
3.3.4. Working with Conditionals: && and ||
3.4. Defining Recursive Functions
3.5. Introducing Function Values
3.5.1. Using Anonymous Function Values
3.5.2. Computing with Aggregate Operators
3.5.3. Composing Functions with >>
3.5.4. Building Functions with Partial Application
3.5.5. Using Local Functions
3.5.6. Using Functions as Abstract Values
3.5.7. Iterating with Aggregate Operators
3.5.8. Abstracting Control with Functions
3.5.9. Using .NET Methods as First-Class Functions
3.6. Getting Started with Pattern Matching
3.6.1. Matching on Structured Values
3.6.2. Guarding Rules and Combining Patterns
3.7. Getting Started with Sequences
3.7.1. Using Range Expressions
3.7.2. Iterating a Sequence
3.7.3. Transforming Sequences with Aggregate Operators
3.7.4. Which Types Can Be Used as Sequences?
3.7.5. Using Lazy Sequences from External Sources
3.8. Using Sequence Expressions
3.8.1. Creating Sequence Expressions Using for
3.8.2. Enriching Sequence Expressions with Additional Logic
3.8.3. Generating Lists and Arrays Using Sequence Expressions
3.9. Exploring Some Simple Type Definitions
3.9.1. Defining Type Abbreviations
3.9.2. Defining Records
3.9.3. Handling Non-Unique Record Field Names
3.9.4. Cloning Records
3.9.5. Defining Discriminated Unions
3.9.6. Using Discriminated Unions as Records
3.9.7. Defining Multiple Types Simultaneously
3.10. Summary
4. Introducing Imperative Programming
4.1. Imperative Looping and Iterating
4.1.1. Simple for Loops
4.1.2. Simple while Loops
4.1.3. More Iteration Loops over Sequences
4.2. Using Mutable Records
4.2.1. Mutable Reference Cells
4.2.2. Avoiding Aliasing
4.2.3. Hiding Mutable Data
4.3. Using Mutable Locals
4.4. Working with Arrays
4.4.1. Generating and Slicing Arrays
4.4.2. Two-Dimensional Arrays
4.5. Introducing the Imperative .NET Collections
4.5.1. Using Resizeable Arrays
4.5.2. Using Dictionaries
4.5.3. Using Dictionary's TryGetValue
4.5.4. Using Dictionaries with Compound Keys
4.5.5. Some Other Mutable Data Structures
4.6. Exceptions and Controlling Them
4.6.1. Catching Exceptions
4.6.2. Using try . . . finally
4.6.3. Defining New Exception Types
4.7. Having an Effect: Basic I/O
4.7.1. Very Simple I/O: Reading and Writing Files
4.7.2. .NET I/O via Streams
4.7.3. Some Other I/O-Related Types
4.7.4. Using System.Console
4.7.5. Using printf and Friends
4.7.6. Generic Structural Formatting
4.7.7. Cleaning Up with IDisposable, use, and using
4.8. Working with null Values
4.9. Some Advice: Functional Programming with Side Effects
4.9.1. Consider Replacing Mutable Locals and Loops with Recursion
4.9.2. Separate Pure Computation from Side-Effecting Computations
4.9.3. Separate Mutable Data Structures
4.9.4. Not All Side Effects Are Equal
4.9.5. Avoid Combining Imperative Programming and Laziness
4.10. Summary
5. Mastering Types and Generics
5.1. Understanding Generic Type Variables
5.2. Writing Generic Functions
5.3. Understanding Some Important Generic Functions
5.3.1. Generic Comparison
5.3.2. Generic Hashing
5.3.3. Generic Pretty-Printing
5.3.4. Generic Boxing and Unboxing
5.3.5. Generic Binary Serialization via the .NET Libraries
5.4. Making Things Generic
5.4.1. Generic Algorithms through Explicit Arguments
5.4.2. Generic Algorithms through Abstract Object Types
5.4.3. Arithmetic Operators and Generic Algorithms through Inlining
5.5. Understanding .NET Types
5.5.1. Reference Types and Value Types
5.5.2. Other Flavors of .NET Types
5.6. Understanding Subtyping
5.6.1. Casting Up Statically
5.6.2. Casting Down Dynamically
5.6.3. Performing Type Tests via Pattern Matching
5.6.4. Knowing When Upcasts Are Applied Automatically
5.6.5. Flexible Types
5.7. Units of Measure
5.8. Troubleshooting Type-Inference Problems
5.8.1. Using a Visual Editing Environment
5.8.2. Using Type Annotations
5.8.3. Understanding the Value Restriction
5.8.4. Working Around the Value Restriction
5.8.4.1. Technique 1: Constrain Values to Be Nongeneric
5.8.4.2. Technique 2: Ensure Generic Functions Have Explicit Arguments
5.8.4.3. Technique 3: Add Dummy Arguments to Generic Functions When Necessary
5.8.4.4. Technique 4: Add Explicit Type Arguments When Necessary
5.8.5. Understanding Generic Overloaded Operators
5.9. Summary
6. Working with Objects and Modules
6.1. Getting Started with Objects and Members
6.2. Using Classes
6.3. Adding Further Object Notation to Your Types
6.3.1. Working with Indexer Properties
6.3.2. Adding Overloaded Operators
6.3.3. Using Named and Optional Arguments
6.3.4. Using Optional Property Settings
6.3.5. Adding Method Overloading
6.4. Defining Object Types with Mutable State
6.5. Getting Started with Object Interface Types
6.5.1. Defining New Object Interface Types
6.5.2. Implementing Object Interface Types Using Object Expressions
6.5.3. Implementing Object Interface Types Using Concrete Types
6.5.4. Using Common Object Interface Types from the .NET Libraries
6.5.5. Understanding Hierarchies of Object Interface Types
6.6. More Techniques to Implement Objects
6.6.1. Combining Object Expressions and Function Parameters
6.6.2. Defining Partially Implemented Class Types
6.6.3. Using Partially Implemented Types via Delegation
6.6.4. Using Partially Implemented Types via Implementation Inheritance
6.7. Using Modules and Static Members
6.8. Extending Existing Types and Modules
6.9. Working with F# Objects and .NET Types
6.9.1. Structs
6.9.2. Delegates
6.9.3. Enums
6.10. Summary
7. Encapsulating and Packaging Your Code
7.1. Hiding Things Away
7.1.1. Hiding Things with Local Definitions
7.1.2. Hiding Things with Accessibility Annotations
7.2. Using Namespaces and Modules
7.2.1. Putting Your Code in a Namespace
7.2.2. Using Files as Modules
7.3. Creating Assemblies, DLLs, and EXEs
7.3.1. Compiling EXEs
7.3.2. Compiling DLLs
7.3.3. Mixing Scripting and Compiled Code
7.3.4. Choosing Optimization Settings
7.3.5. Generating Documentation
7.3.6. Building Shared Libraries and Using the Global Assembly Cache
7.3.7. Using Static Linking
7.4. Using Signature Types and Files
7.4.1. Using Explicit Signature Types and Signature Files
7.4.2. When Are Signature Types Checked?
7.5. Packaging Applications
7.5.1. Packaging Different Kinds of Code
7.5.2. Using Data and Configuration Settings
7.6. Summary
8. Mastering F#: Common Techniques
8.1. Equality, Hashing, and Comparison
8.1.1. Asserting Equality, Hashing, and Comparison Using Attributes
8.1.2. Fully Customizing Equality, Hashing, and Comparison on a Type
8.1.3. Suppressing Equality, Hashing, and Comparison on a Type
8.1.4. Customizing Generic Collection Types
8.2. Efficient Precomputation and Caching
8.2.1. Precomputation and Partial Application
8.2.2. Precomputation and Objects
8.2.3. Memoizing Computations
8.2.4. Lazy Values
8.2.5. Other Variations on Caching and Memoization
8.3. Cleaning Up Resources
8.3.1. Cleaning Up with use
8.3.2. Managing Resources with More Complex Lifetimes
8.3.3. Cleaning Up Internal Objects
8.3.4. Cleaning Up Unmanaged Objects
8.3.5. Cleaning Up in Sequence Expressions
8.3.6. Using using
8.4. Stack as a Resource: Tail Calls and Recursion
8.4.1. Tail Recursion and List Processing
8.4.2. Tail Recursion and Object-Oriented Programming
8.4.3. Tail Recursion and Processing Unbalanced Trees
8.4.4. Using Continuations to Avoid Stack Overflows
8.4.5. Another Example: Processing Syntax Trees
8.5. Events
8.5.1. Events as First-Class Values
8.5.2. Creating and Publishing Events
8.6. Summary
9. Introducing Language-Oriented Programming
9.1. Using XML as a Concrete Language Format
9.1.1. Using the System.Xml Namespace
9.1.2. From Concrete XML to Abstract Syntax
9.2. Working with Abstract Syntax Representations
9.2.1. Abstract Syntax Representations: Less Is More
9.2.2. Processing Abstract Syntax Representations
9.2.3. Transformational Traversals of Abstract Syntax Representations
9.2.4. Using On-Demand Computation with Abstract Syntax Trees
9.2.5. Caching Properties in Abstract Syntax Trees
9.2.6. Memoizing Construction of Syntax Tree Nodes
9.3. Introducing Active Patterns
9.3.1. Converting the Same Data to Many Views
9.3.2. Matching on .NET Object Types
9.3.3. Defining Partial and Parameterized Active Patterns
9.3.4. Hiding Abstract Syntax Implementations with Active Patterns
9.4. Embedded Computational Languages with Workflows
9.4.1. An Example: Success/Failure Workflows
9.4.2. Defining a Workflow Builder
9.4.3. Workflows and Untamed Side Effects
9.4.4. Example: Probabilistic Workflows
9.4.5. Combining Workflows and Resources
9.4.6. Recursive Workflow Expressions
9.5. Using F# Reflection
9.5.1. Reflecting on Types
9.5.2. Schema Compilation by Reflecting on Types
9.5.3. Using the F# Dynamic Reflection Operators
9.6. Using F# Quotations
9.6.1. Example: Using F# Quotations for Error Estimation
9.6.2. Resolving Top Definitions
9.7. Summary
10. Using the F# and .NET Libraries
10.1. A High-Level Overview
10.1.1. Namespaces from the .NET Framework
10.1.2. Namespaces from the F# Libraries
10.2. Using the System Types
10.3. Using Regular Expressions and Formatting
10.3.1. Matching with System.Text.RegularExpressions
10.3.2. Formatting Strings Using .NET Formatting
10.3.3. Encoding and Decoding Unicode Strings
10.3.4. Encoding and Decoding Binary Data
10.4. Using Further F# and .NET Data Structures
10.4.1. System.Collections.Generic and Other .NET Collections
10.5. Introducing Microsoft.FSharp.Math
10.5.1. Using Matrices and Vectors
10.5.2. Using Operator Overloads on Matrices and Vectors
10.6. Supervising and Isolating Execution
10.7. Further Libraries for Reflective Techniques
10.7.1. Using General Types
10.7.2. Using Microsoft.FSharp.Reflection
10.8. Some Other .NET Types You May Encounter
10.9. Some Other .NET Libraries
10.10. Summary
11. Building Graphical User Interfaces
11.1. Writing "Hello, World!" in a Click
11.2. Understanding the Anatomy of a Graphical Application
11.3. Composing User Interfaces
11.4. Drawing Applications
11.5. Writing Your Own Controls
11.5.1. Developing a Custom Control
11.5.2. Anatomy of a Control
11.6. Displaying Samples from Sensors
11.6.1. Building the GraphControl: The Model
11.6.2. Building the GraphControl: Style Properties and Controller
11.6.3. Building the GraphControl: The View
11.6.4. Putting It Together
11.7. Creating a Mandelbrot Viewer
11.7.1. Computing Mandelbrot
11.7.2. Setting Colors
11.7.3. Creating the Visualization Application
11.7.4. Creating the Application Plumbing
11.8. Windows Presentation Foundation
11.8.1. When GUIs Meet the Web
11.8.2. Drawing
11.8.3. Controls
11.8.4. Bitmaps and Images
11.8.5. Final Considerations
11.9. Summary
12. Working with Symbolic Representations
12.1. Symbolic Differentiation and Expression Rendering
12.1.1. Modeling Simple Algebraic Expressions
12.1.2. Implementing Local Simplifications
12.1.3. A Richer Language of Algebraic Expressions
12.1.4. Parsing Algebraic Expressions
12.1.5. Simplifying Algebraic Expressions
12.1.6. Symbolic Differentiation of Algebraic Expressions
12.1.7. Rendering Expressions
12.1.7.1. Converting to VisualExpr
12.1.7.2. Rendering
12.1.8. Building the User Interface
12.2. Verifying Circuits with Propositional Logic
12.2.1. Representing Propositional Logic
12.2.2. Evaluating Propositional Logic Naively
12.2.3. From Circuits to Propositional Logic
12.2.4. Checking Simple Properties of Circuits
12.2.5. Representing Propositional Formulae Efficiently Using BDDs
12.2.6. Circuit Verification with BDDs
12.3. Summary
13. Reactive, Asynchronous, and Parallel Programming
13.1. Introducing Some Terminology
13.2. Using and Designing Background Workers
13.2.1. Building a Simpler Iterative Worker
13.2.2. Raising Additional Events from Background Workers
13.2.3. Connecting a Background Worker to a GUI
13.3. Introducing Asynchronous and Parallel Computations
13.3.1. Fetching Multiple Web Pages in Parallel, Asynchronously
13.3.2. Understanding Thread Hopping
13.3.3. Under the Hood: What Are Asynchronous Computations?
13.3.4. Parallel File Processing Using Asynchronous Workflows
13.3.5. Running Asynchronous Computations
13.3.6. Common I/O Operations in Asynchronous Workflows
13.3.7. Under the Hood: Implementing Async.Parallel
13.3.8. Using async for CPU Parallelism with Fixed Tasks
13.3.9. Understanding Exceptions and Cancellation
13.4. Passing and Processing Messages
13.4.1. Introducing Message Processing
13.4.2. Creating Objects That React to Messages
13.4.3. Scanning Mailboxes for Relevant Messages
13.4.4. Example: Asynchronous Web Crawling
13.5. Using Shared-Memory Concurrency
13.5.1. Creating Threads Explicitly
13.5.2. Shared Memory, Race Conditions, and the .NET Memory Model
13.5.3. Using Locks to Avoid Race Conditions
13.5.4. Using ReaderWriterLock
13.5.5. Some Other Concurrency Primitives
13.6. Summary
14. Building Smart Web Applications
14.1. Serving Static Web Content
14.2. Serving Dynamic Web Content with ASP.NET
14.2.1. Understanding the Languages Used in ASP.NET
14.2.2. A Simple ASP.NET Web Application
14.2.3. Deploying and Running the Application
14.2.4. Using Code-Behind Files
14.3. Using ASP.NET Input Controls
14.4. Displaying Data from Databases
14.5. Going Further with ASP.NET
14.5.1. ASP.NET Directives
14.5.2. Server Controls
14.5.3. Debugging, Profiling, and Tracing
14.5.4. Understanding the ASP.NET Event Model
14.5.5. Maintaining the View State
14.5.6. Understanding the Provider Model
14.5.6.1. Configuring the Provider Database
14.5.7. Creating Custom ASP.NET Server Controls
14.6. Building Ajax Rich Client Applications
14.6.1. More on the WebSharper Platform
14.6.1.1. Getting Started with WebSharper
14.6.1.2. WebSharper Pagelets
14.6.1.3. Calling Server Code from the Client
14.7. WebSharper Formlets
14.7.1.
14.7.1.1. .NET Proxies and JavaScript Stubs
14.7.1.2. Automated Resource Tracking and Handling
14.7.1.3. Dependent Formlets and Flowlets
14.8. Using WSDL Web Services
14.8.1. Consuming Web Services
14.8.2. Calling Web Services Asynchronously
14.9. Summary
15. Working with Data
15.1. Querying In-Memory Data Structures
15.1.1. Select/Where/From Queries Using Aggregate Operators
15.1.2. Using Aggregate Operators in Queries
15.1.3. Accumulating Using Folding Operators
15.1.4. Expressing Some Queries Using Sequence Expressions
15.2. Using Databases to Manage Data
15.2.1. Choosing Your Database Engine
15.2.2. Understanding ADO.NET
15.2.3. Establishing Connections to a Database Engine
15.2.4. Creating a Database
15.2.5. Creating Tables and Inserting and Fetching Records
15.2.6. Using Untyped Datasets
15.2.7. Generating Typed Datasets Using xsd.exe
15.2.8. Using Stored Procedures
15.2.9. Using Data Grids
15.3. Working with Databases in Visual Studio
15.3.1. Creating a Database
15.3.2. Visual Data Modeling: Adding Relationships
15.4. Accessing Relational Data with Linq Queries
15.4.1. Generating the Object/Relational Mapping
15.4.2. Building the DataContext Instance
15.4.3. Using LINQ from F#
15.5. Working with XML as a Generic Data Format
15.5.1. Constructing XML via LINQ
15.5.2. Storing, Loading, and Traversing LinqToXml Documents
15.5.3. Querying XML
15.6. Summary
16. Lexing and Parsing
16.1. Processing Line-Based Input
16.1.1. On-Demand Reading of Files
16.1.2. Using Regular Expressions
16.2. Tokenizing with FsLex
16.2.1. The FsLex Input in More Detail
16.2.2. Generating a Simple Token Stream
16.2.3. Tracking Position Information Correctly
16.2.4. Handling Comments and Strings
16.3. Recursive-Descent Parsing
16.3.1. Limitations of Recursive-Descent Parsers
16.4. Parsing with FsYacc
16.4.1. The Lexer for Kitty
16.4.2. The Parser for Kitty
16.4.3. Parsing Lists
16.4.4. Resolving Conflicts, Operator Precedence, and Associativity
16.4.5. Putting It Together
16.5. Binary Parsing and Pickling Using Combinators
16.6. Summary
17. Interoperating with C and COM
17.1. Common Language Runtime
17.2. Memory Management at Runtime
17.3. COM Interoperability
17.4. Platform Invoke
17.4.1. Getting Started with PInvoke
17.4.2. Data Structures
17.4.3. Marshalling Strings
17.4.4. Function Pointers
17.4.5. PInvoke Memory Mapping
17.4.6. Wrapper Generation and Limits of PInvoke
17.5. Summary
18. Debugging and Testing F# Programs
18.1. Debugging F# Programs
18.1.1. Using Advanced Features of the Visual Studio Debugger
18.1.2. Instrumenting Your Program with the System.Diagnostics Namespace
18.1.3. Debugging Concurrent and Graphical Applications
18.2. Debugging and Testing with F# Interactive
18.2.1. Controlling F# Interactive
18.2.2. Some Common F# Interactive Directives
18.2.3. Understanding How F# Interactive Compiles Code
18.2.4. F# Interactive and Visual Studio
18.3. Unit Testing
18.4. Summary
19. Designing F# Libraries
19.1. Designing Vanilla .NET Libraries
19.2. Understanding Functional Design Methodology
19.2.1.
19.2.1.1.
19.2.1.1.1. Understanding Where Functional Programming Comes From
19.2.1.1.2. Understanding Functional Design Methodology
19.3. Applying the .NET Library Design Guidelines to F#
19.3.1.
19.3.1.1.
19.3.1.1.1. Recommendation: Use the .NET Naming and Capitalization Conventions Where Possible
19.3.1.1.2. Recommendation: Avoid Using Underscores in Names
19.3.1.1.3. Recommendation: Follow the .NET Guidelines for Exceptions
19.3.1.1.4. Recommendation: Consider Using Option Values for Return Types Instead of Raising Exceptions
19.3.1.1.5. Recommendation: Follow the .NET Guidelines for Value Types
19.3.1.1.6. Recommendation: Consider Using Explicit Signature Files for Your Framework
19.3.1.1.7. Recommendation: Consider Avoiding the Use of Implementation Inheritance for Extensibility
19.3.1.1.8. Recommendation: Use Properties and Methods for Attributes and Operations Essential to a Type
19.3.1.1.9. Recommendation: Avoid Revealing Concrete Data Representations Such as Records
19.3.1.1.10. Recommendation: Use Active Patterns to Hide the Implementations of Discriminated Unions
19.3.1.1.11. Recommendation: Use Object Interface Types Instead of Tuples or Records of Functions
19.3.1.1.12. Recommendation: Understand When Currying Is Useful in Functional Programming APIs
19.3.1.1.13. Recommendation: Use Tuples for Return Values, Arguments, and Intermediate Values
19.4. Some Recommended Coding Idioms
19.4.1.
19.4.1.1.
19.4.1.1.1. Recommendation: Use the Standard Operators
19.4.1.1.2. Recommendation: Place the Pipeline Operator |> at the Start of a Line
19.4.1.1.3. Recommendation: Format Object Expressions Using the member Syntax
19.5. Summary
A. F# Brief Language Guide
A.1. Comments and Attributes
A.2. Basic Types and Literals
A.3. Types
A.4. Patterns and Matching
A.5. Functions, Composition, and Pipelining
A.6. Binding and Control Flow
A.7. Exceptions
A.8. Tuples, Arrays, Lists, and Collections
A.9. Operators
A.10. Type Definitions and Objects
A.11. Namespaces and Modules
A.12. Sequence Expressions and Workflows
Search in book...
Toggle Font Controls
Playlists
Add To
Create new playlist
Name your new playlist
Playlist description (optional)
Cancel
Create playlist
Sign In
Email address
Password
Forgot Password?
Create account
Login
or
Continue with Facebook
Continue with Google
Sign Up
Full Name
Email address
Confirm Email Address
Password
Login
Create account
or
Continue with Facebook
Continue with Google
Prev
Previous Chapter
About the Authors
Next
Next Chapter
Acknowledgments
About the Technical Reviewer
He lives in Southern California, and works as a .Net developer.
Add Highlight
No Comment
..................Content has been hidden....................
You can't read the all page of ebook, please click
here
login for view all page.
Day Mode
Cloud Mode
Night Mode
Reset