Expert F#

Book description

Expert F# is about practical programming in a beautiful language that puts the power and elegance of functional programming into the hands of .NET developers. In combination with .NET, F# achieves unrivaled levels of programmer productivity and program clarity. This books serves as

  • The authoritative guide to F# by the designer of F#

  • A comprehensive reference of F# concepts, syntax, and features

  • A treasury of expert F# techniques for practical, real–world programming

While inspired by OCaml, F# isn't just another functional programming language. Drawing on many of the strengths of both OCaml and .NET, it's a general–purpose language ideal for real–world development. F# integrates functional, imperative, and object–oriented programming styles so you can flexibly and elegantly solve programming problems, and brings .NET development alive with interactive execution. Whatever your background, you'll find that F# is easy to learn, fun to use, and extraordinarily powerful. F# will help change the way you think about and go about programming.

Written by F#’s designer and two active contributors, Expert F# is the authoritative, comprehensive, and in–depth guide to the language and its use. Designed to help others become experts, the book gives a thorough introduction to the F# language from quick essentials to in–depth advanced topics such as active pattern matching, aggregate data types and operators, sequence expressions, lazy values, mutable data and side–effects, generics, type augmentations, functional decomposition and code organization.

The second half of the book is devoted to examining the practical application of F#, providing elegant solutions to common programming tasks including user interface implementation, data access, web and distributed programming, symbolic and numerical computations, concurrent programming, testing, profiling, and interoperability with other languages. The latest hot developments in F# and .NET are also addressed, including Active Patterns, implicit class construction, integration with LINQ over relational data, meta programming and useful tips for working with Visual Studio and F# command–line tools.

The worlds foremost experts in F# show you how to program in F# the way they do!

What you'll learn

    How to use F# for functional, imperative, and object–oriented programming

  • How to code elegant F# solutions with expert technique and style

  • How to develop Windows, web, graphics, and database applications in F#

  • How to do numerical, concurrent, lexical, and symbolic processing in F#

  • How to interoperate with C and COM

Who this book is for

This book is for anyone interested in state–of–the art .NET programming. Professional programmers will find it engrossing. F# provides invaluable insight into the future of both C# and VB, which are now adopting some (but far from all) of the functional features of F#. Once they learn F#, few feel like returning to either C# or VB. The academic community will find F# the answer to a decades–long prayer: a language suitable for teaching computer science that also excites and empowers students because it can be used not just in the classroom, but also in the real world.

Table of contents

  1. Title Page
  2. Dedication
  3. Contents at a Glance
  4. Contents
  5. Foreword
  6. About the Authors
  7. About the Technical Reviewer
  8. Acknowledgments
  9. CHAPTER 1: Introduction
    1. The Genesis of F#
    2. About This Book
    3. Who This Book Is For
  10. CHAPTER 2: Getting Started with F# and .NET
    1. Creating Your First F# Program
    2. Using .NET Libraries from F#
    3. Summary
  11. CHAPTER 3: Introducing Functional Programming
    1. Getting Started with F# Arithmetic
    2. Introducing Simple Strings
    3. Working with Lists and Options
    4. Working with Conditionals: && and ||
    5. Defining Recursive Functions
    6. Introducing Function Values
    7. Getting Started with Pattern Matching
    8. Getting Started with Sequences
    9. Using Sequence Expressions
    10. Exploring Some Simple Type Definitions
    11. Summary
  12. CHAPTER 4: Introducing Imperative Programming
    1. Imperative Looping and Iterating
    2. Using Mutable Records
    3. Using Mutable Locals
    4. Working with Arrays
    5. Introducing the Imperative .NET Collections
    6. Exceptions and Controlling Them
    7. Having an Effect: Basic I/O
    8. Working with null Values
    9. Some Advice: Functional Programming with Side Effects
    10. Summary
  13. CHAPTER 5: Mastering Types and Generics
    1. Understanding Generic Type Variables
    2. Writing Generic Functions
    3. Understanding Some Important Generic Functions
    4. Making Things Generic
    5. Understanding .NET Types
    6. Understanding Subtyping
    7. Troubleshooting Type Inference Problems
    8. Summary
  14. CHAPTER 6: Working with Objects and Modules
    1. Getting Started with Objects and Members
    2. Using Constructed Classes
    3. Adding Further Object Notation to Your Types
    4. Defining Object Types with Mutable State
    5. Getting Started with Object Interface Types
    6. More Techniques to Implement Objects
    7. Using Modules and Static Members
    8. Extending Existing Types and Modules
    9. Working with F# Objects and .NET Types
    10. Summary
  15. CHAPTER 7: Encapsulating and Packaging Your Code
    1. Hiding Things Away
    2. Using Namespaces and Modules
    3. Using Signature Types and Files
    4. Creating Assemblies, DLLs, and EXEs
    5. Packaging Applications
    6. Summary
  16. CHAPTER 8: Mastering F#: Common Techniques
    1. Equality, Hashing, and Comparison
    2. Efficient Precomputation and Caching
    3. Cleaning Up Resources
    4. Stack As a Resource: Tail Calls and Recursion
    5. Events and Wiring
    6. Summary
  17. CHAPTER 9: Introducing Language-Oriented Programming
    1. Using XML As a Concrete Language Format
    2. Working with Abstract Syntax Representations
    3. Introducing Active Patterns
    4. Embedded Computational Languages with Workflows
    5. Using F# Reflection
    6. Using F# Quotations
    7. Summary
  18. CHAPTER 10: Using the F# and .NET Libraries
    1. A High-Level Overview
    2. Using the System Types
    3. Using Regular Expressions and Formatting
    4. Using Further F# and .NET Data Structures
    5. Introducing Microsoft.FSharp.Math
    6. Supervising and Isolating Execution
    7. Further Libraries for Reflective Techniques
    8. Some Other .NET Types You May Encounter
    9. Some Other .NET Libraries
    10. Summary
  19. CHAPTER 11: Working with Windows Forms and Controls
    1. Writing "Hello, World!" in a Click
    2. Understanding the Anatomy of a Graphical Application
    3. Composing User Interfaces
    4. Drawing Applications
    5. Writing Your Own Controls
    6. Displaying Samples from Sensors
    7. Creating a Mandelbrot Viewer
    8. Summary
  20. CHAPTER 12: Working with Symbolic Representations
    1. Symbolic Differentiation and Expression Rendering
    2. Verifying Circuits with Propositional Logic
    3. Summary
  21. CHAPTER 13: Reactive, Asynchronous, and Concurrent Programming
    1. Introducing Some Terminology
    2. Using and Designing Background Workers
    3. Introducing Asynchronous Computations
    4. Passing and Processing Messages
    5. Using Shared-Memory Concurrency
    6. Summary
  22. CHAPTER 14: Building Web Applications
    1. Serving Static Web Content
    2. Serving Dynamic Web Content with ASP.NET
    3. Using ASP.NET Input Controls
    4. Displaying Data from Databases
    5. Going Further with ASP.NET
    6. Building Ajax Rich Client Applications
    7. Using Web Services
    8. Summary
  23. CHAPTER 15: Working with Data
    1. Querying In-Memory Data Structures
    2. Using Databases to Manage Data
    3. Working with Databases in Visual Studio
    4. Accessing Relational Data with F# LinqToSql
    5. Working with XML As a Generic Data Format
    6. Summary
  24. CHAPTER 16: Lexing and Parsing
    1. Processing Line-Based Input
    2. Tokenizing with FsLex
    3. Recursive-Descent Parsing
    4. Parsing with FsYacc
    5. Binary Parsing and Pickling Using Combinators
    6. Summary
  25. CHAPTER 17: Interoperating with C and COM
    1. Common Language Runtime
    2. Memory Management at Run Time
    3. COM Interoperability
    4. Platform Invoke
    5. Summary
  26. CHAPTER 18: Debugging and Testing F# Programs
    1. Debugging F# Programs
    2. Debugging and Testing with F# Interactive
    3. Unit Testing
    4. Summary
  27. CHAPTER 19: Designing F# Libraries
    1. Designing Vanilla .NET Libraries
    2. Understanding Functional Design Methodology
    3. Applying the .NET Design Guidelines to F#
    4. Some Recommended Coding Idioms
    5. Summary
  28. APPENDIX: F# Brief Language Guide
    1. Comments and Attributes
    2. Basic Types and Literals
    3. Types
    4. Patterns and Matching
    5. Functions, Composition, and Pipelining
    6. Binding and Control Flow
    7. Exceptions
    8. Tuples, Arrays, Lists, and Collections
    9. Operators
    10. Type Definitions and Objects
    11. Namespaces and Modules
    12. Sequence Expressions and Workflows
  29. Index

Product information

  • Title: Expert F#
  • Author(s): Don Syme, Adam Granicz, Antonio Cisternino
  • Release date: December 2007
  • Publisher(s): Apress
  • ISBN: 9781590598504