You are previewing Beginning F#.
O'Reilly logo
Beginning F#

Book Description

Functional programming is perhaps the next big wave in application development. As experienced developers know, functional programming makes its mark by allowing application builders to develop solutions to complicated programming situations cleanly and efficiently. A rich history of functional languages, including Erlang and OCaml, leads the way to F#, Microsoft's effort to bring the elegance and focus of functional programming into the world of managed code and .NET.

With Beginning F#, you have a companion that that will help you explore F# and functional programming in a .NET environment. This book is both a comprehensive introduction to all aspects of the language and an incisive guide to using F# for real-world professional development.

Reviewed by Don Syme, the chief architect of F# at Microsoft Research, Beginning F# is a great foundation for exploring functional programming and its role in the future of application development.

Table of Contents

  1. Copyright
  2. Foreword
  3. About the Author
  4. About the Technical Reviewer
  5. Acknowledgments
  6. Preface
  7. 1. Introduction
    1. 1.1. What Is Functional Programming?
    2. 1.2. Why Is Functional Programming Important?
    3. 1.3. What Is F#?
    4. 1.4. Who Is Using F#?
    5. 1.5. Who Is This Book For?
    6. 1.6. What's Next?
  8. 2. How to Obtain, Install, and Use F#
    1. 2.1. Obtaining F#
    2. 2.2. Installing F# on Windows with Visual Studio 2008
    3. 2.3. Installing F# on Linux
    4. 2.4. Using F# in Different Ways
      1. 2.4.1. Visual Studio
      2. 2.4.2. SharpDevelop
      3. 2.4.3. F# Interactive Command-Line
    5. 2.5. The Examples in This Book
    6. 2.6. Summary
  9. 3. Functional Programming
    1. 3.1. Literals
    2. 3.2. Functions
    3. 3.3. Identifiers and let Bindings
      1. 3.3.1. Identifier Names
      2. 3.3.2. Scope
      3. 3.3.3. Capturing Identifiers
      4. 3.3.4. The use Binding
    4. 3.4. Recursion
    5. 3.5. Operators
    6. 3.6. Function Application
    7. 3.7. Partial Application of Functions
    8. 3.8. Pattern Matching
    9. 3.9. Control Flow
    10. 3.10. Lists
      1. 3.10.1. Pattern Matching Against Lists
      2. 3.10.2. List Comprehensions
    11. 3.11. Types and Type Inference
    12. 3.12. Defining Types
      1. 3.12.1. Tuple and Record Types
      2. 3.12.2. Union or Sum Types
      3. 3.12.3. Type Definitions with Type Parameters
      4. 3.12.4. Recursive Type Definitions
    13. 3.13. Active Patterns
      1. 3.13.1. Complete Active Patterns
      2. 3.13.2. Incomplete Active Patterns
    14. 3.14. Units of Measure
    15. 3.15. Exceptions and Exception Handling
    16. 3.16. Lazy Evaluation
    17. 3.17. Summary
  10. 4. Imperative Programming
    1. 4.1. The unit Type
    2. 4.2. The mutable Keyword
    3. 4.3. Defining Mutable Record Types
    4. 4.4. The ref Type
    5. 4.5. Arrays
    6. 4.6. Array Comprehensions
    7. 4.7. Control Flow
    8. 4.8. Calling Static Methods and Properties from .NET Libraries
    9. 4.9. Using Objects and Instance Members from .NET Libraries
    10. 4.10. Using Indexers from .NET Libraries
    11. 4.11. Working with Events from .NET Libraries
    12. 4.12. Pattern Matching over .NET Types
    13. 4.13. The |> Operator
    14. 4.14. Summary
  11. 5. Object-Oriented Programming
    1. 5.1. Records As Objects
    2. 5.2. F# Types with Members
    3. 5.3. Object Expressions
    4. 5.4. Defining Classes
    5. 5.5. Optional Parameters
    6. 5.6. Defining Interfaces
    7. 5.7. Implementing Interfaces
    8. 5.8. Classes and Inheritance
    9. 5.9. Methods and Inheritance
    10. 5.10. Accessing the Base Class
    11. 5.11. Properties and Indexers
    12. 5.12. Overriding Methods from Non-F# Libraries
    13. 5.13. Abstract Classes
    14. 5.14. Classes and Static Methods
    15. 5.15. Classes with Explicit Fields and Constructors
    16. 5.16. Casting
    17. 5.17. Type Tests
    18. 5.18. Type Annotations for Subtyping
    19. 5.19. Defining Delegates
    20. 5.20. Structs
    21. 5.21. Enums
    22. 5.22. Summary
  12. 6. Organizing, Annotating, and Quoting Code
    1. 6.1. Modules
    2. 6.2. Namespaces
    3. 6.3. Opening Namespaces and Modules
    4. 6.4. Giving Modules Aliases
    5. 6.5. Signature Files
    6. 6.6. Private and Internal let Bindings and Members
    7. 6.7. Module Scope
    8. 6.8. Module Execution
    9. 6.9. Optional Compilation
    10. 6.10. Comments
    11. 6.11. Doc Comments
    12. 6.12. Comments for Cross Compilation
    13. 6.13. Custom Attributes
    14. 6.14. Quoted Code
    15. 6.15. Summary
  13. 7. The F# Libraries
    1. 7.1. The Native F# Library FSharp.Core.dll
      1. 7.1.1. The Microsoft.FSharp.Core.Operators Module
    2. 7.2. Arithmetic Operators
    3. 7.3. Floating-Point Arithmetic Functions
    4. 7.4. Tuple Functions
    5. 7.5. The Conversion Functions
    6. 7.6. The Logical Or and And Operators
      1. 7.6.1. The Microsoft.FSharp.Reflection Module
    7. 7.7. Reflection Over Types
    8. 7.8. Reflection Over Values
      1. 7.8.1. The Microsoft.FSharp.Collections.Seq Module
    9. 7.9. The map and iter Functions
    10. 7.10. The concat Function
    11. 7.11. The fold Function
    12. 7.12. The exists and forall Functions
    13. 7.13. The filter, find, and tryFind Functions
    14. 7.14. The choose Function
    15. 7.15. The init and initInfinite Functions
    16. 7.16. The unfold Function
    17. 7.17. The generate Function
    18. 7.18. The cast Function
      1. 7.18.1. The Microsoft.FSharp.Text.Printf Module
      2. 7.18.2. The Microsoft.FSharp.Control.Event Module
    19. 7.19. Creating and Handling Events
    20. 7.20. The filter Function
    21. 7.21. The partition Function
    22. 7.22. The map Function
    23. 7.23. The Power Pack Library FSharp.PowerPack.dll
      1. 7.23.1. The Microsoft.FSharp.Math Namespace
    24. 7.24. Summary
  14. 8. User Interfaces
    1. 8.1. Introducing WinForms
    2. 8.2. Drawing WinForms
    3. 8.3. Working with Controls in WinForms
    4. 8.4. Using the Visual Studio Form Designer's Forms in F#
    5. 8.5. Working with WinForms Events and the Event Module
    6. 8.6. Creating New Forms Classes
    7. 8.7. Introducing Windows Presentation Foundation
    8. 8.8. Introducing Windows Presentation Foundation 3D
    9. 8.9. Introducing GTK#
    10. 8.10. Introducing ASP.NET
    11. 8.11. Creating an IHttpHandler
    12. 8.12. Working with ASP.NET Web Forms
    13. 8.13. Summary
  15. 9. Data Access
    1. 9.1. The System.Configuration Namespace
    2. 9.2. The System.IO Namespace
    3. 9.3. Using Sequences with System.IO
    4. 9.4. The System.Xml Namespace
    5. 9.5. ADO.NET
    6. 9.6. Data Binding
    7. 9.7. Data Binding and the DataGridView Control
    8. 9.8. ADO.NET Extensions
    9. 9.9. Introducing LINQ
    10. 9.10. Using LINQ to XML
    11. 9.11. Summary
  16. 10. Paral lel Programming
    1. 10.1. Threads, Memory, Locking, and Blocking
    2. 10.2. Reactive Programming
    3. 10.3. Data Parallelism
    4. 10.4. Asynchronous Programming
    5. 10.5. Message Passing
    6. 10.6. Summary
  17. 11. Distributed Applications
    1. 11.1. Networking Overview
    2. 11.2. Using TCP/IP Sockets
    3. 11.3. Using HTTP
    4. 11.4. Using HTTP with Google Spreadsheets
    5. 11.5. Using HTTP Posts
    6. 11.6. Using HTTP Asynchronously
    7. 11.7. Creating Web Services
    8. 11.8. Windows Communication Foundation
    9. 11.9. Hosting WCF Services
    10. 11.10. Summary
  18. 12. Language-Oriented Programming
    1. 12.1. What Is Language-Oriented Programming?
    2. 12.2. Data Structures as Little Languages
      1. 12.2.1. A Data Structure–Based Language Implementation
    3. 12.3. Metaprogramming with Quotations
    4. 12.4. Implementing a Compiler and an Interpreter for an Arithmetic-Language
      1. 12.4.1. The Abstract Syntax Tree
      2. 12.4.2. Interpreting the AST
      3. 12.4.3. Compiling the AST
      4. 12.4.4. Compilation vs. Interpretation
    5. 12.5. Summary
  19. 13. Parsing Text
    1. 13.1. Parsing CSV Format
    2. 13.2. Language Definition for the Other Examples
    3. 13.3. Using fslex.exe and fsyacc.exe
      1. 13.3.1. Tokenizing the Text: Fslex
      2. 13.3.2. Generating a Parser: Fsyacc
      3. 13.3.3. Using the Parser
    4. 13.4. FParsec Library
    5. 13.5. Summary
  20. 14. Compatibility and Advanced Interoperation
    1. 14.1. Calling F# Libraries from C#
      1. 14.1.1. Returning Tuples
      2. 14.1.2. Exposing Functions That Take Functions As Parameters
      3. 14.1.3. Using Union Types
      4. 14.1.4. Using F# Lists
      5. 14.1.5. Defining Types in a Namespace
      6. 14.1.6. Defining Classes and Interfaces
    2. 14.2. Calling Using COM Objects
    3. 14.3. Using COM Style APIs
    4. 14.4. Using P/Invoke
    5. 14.5. Using Inline IL
    6. 14.6. Using F# from Native Code via COM
    7. 14.7. Hosting the CLR
    8. 14.8. Summary