You are previewing F# for C# Developers.

F# for C# Developers

Cover of F# for C# Developers by Tao Liu Published by Microsoft Press
  1. Special Upgrade Offer
  2. A Note Regarding Supplemental Files
  3. Foreword
  4. Introduction
    1. Who Should Read This Book
    2. Who Should Not Read This Book
    3. Organization of This Book
      1. Finding Your Best Starting Point in This Book
    4. Conventions and Features in This Book
    5. System Requirements
    6. Code Samples
      1. Installing the Code Samples
      2. Using the Code Samples
    7. Acknowledgments
    8. Errata & book support
    9. We want to hear from you
    10. Stay in touch
  5. I. C# and F#
    1. 1. C# and F# Data Structures
      1. Basic Data Types
      2. Flow Control
      3. Run Your Program
      4. Some Useful Add-ins
      5. List, Sequence, and Array Data Structures
      6. Other F# Types
    2. 2. Using F# for Object-Oriented Programming
      1. Using Classes
      2. Using Inheritance
      3. Using Abstract and Sealed Classes
      4. Creating an Instance
      5. Using Type Casting
      6. Defining an Interface
      7. Using F# Generic Types and Constraints
      8. Defining Structure
      9. Using Extension Methods
      10. Using Operator Overloading
      11. Using Delegates and Events
      12. Interoperating with a C# Project
      13. Real-World Samples
    3. 3. F# and Design Patterns
      1. Using Object-Oriented Programming and Design Patterns
      2. Working with F# and Design Patterns
      3. Writing Design Patterns: Additional Notes
  6. II. F#’s Unique Features
    1. 4. Type Providers
      1. Using the LINQ-to-SQL Type Provider
      2. SQL Entity Type Provider
      3. WSDL Type Provider
      4. OData Type Provider
      5. Other Type Providers
      6. Query
      7. Using a Type Provider to Connect to the Windows Azure Marketplace
    2. 5. Write Your Own Type Provider
      1. What Is a Type Provider?
      2. Setting Up the Development Environment
      3. Exploring the HelloWorld Type Provider
      4. Using the Regular-Expression Type Provider
      5. Using the CSV Type Provider
      6. Using the Excel-File Type Provider
      7. Using the Type-Provider Base Class
      8. Using the Multi-Inheritance Type Provider
      9. Using the XML Type Provider
      10. Using the DGML-File Type Provider
      11. Separating Run Time and Design Time
      12. Generated Type Provider
      13. Using Type-Provider Snippets
      14. Type-Provider Limitations
    3. 6. Other Unique Features
      1. Working with Reference Cells
      2. Working with Object Expressions
      3. Working with Options
      4. Working with Units of Measure
      5. Working with Records
      6. Working with Discriminated Unions
      7. Working with Comparison Operations for a Record, Tuple, and DU
      8. Using Pattern Matching
      9. Working with Active Patterns
      10. Working with Exceptions
      11. Working with a Generic Invoke Function
      12. Working with Asynchronous and Parallel Workflows
      13. Working with Computation Expressions
      14. Using Reflection
      15. Working with Code Quotation
      16. Working with the Observable Module
      17. Using Lazy Evaluation, Partial Functions, and Memoization
      18. Summary
  7. III. Real-World Applications
    1. 7. Portable Library and HTML/JavaScript
      1. Developing Windows Store Applications with F#
      2. Working with HTML5 and WebSharper
    2. 8. Cloud and Service Programming with F#
      1. Introducing Windows Azure
      2. MapReduce
      3. Genetic Algorithms on Cloud
    3. 9. GPGPU with F#
      1. Introducing GPU and GPGPU
      2. CUDA
      3. F# Quotation and Transform
      4. F# Quotation on GPGPU
      5. Using Binomial Trees and the BOPM
      6. Maximum Values in Subarrays
      7. Using the Monte Carlo Simulation to Compute the π Value on a GPU
      8. Useful Resources
      9. In Closing
    4. A. About the Author
  8. Index
  9. About the Author
  10. Special Upgrade Offer
  11. Copyright
O'Reilly logo

Chapter 6. Other Unique Features

In previous chapters, I showed you exciting things you can do in F# as well as various F# data structures. This chapter itemizes the F# data structures and describes them in detail. This chapter is crucial to starting your F# development in full swing.

Working with Reference Cells

You already used the reference cell in Example 1-86 from Chapter 1. In that code, a reference cell was used to wrap a ref parameter. According to the MSDN documentation, a reference cell is a storage structure used to create mutable data. The reference cell definition is shown in Example 6-1, which is actually a record type containing a mutable variable.

Example 6-1. Reference cell definition
type Ref<'a> =
    { mutable contents: 'a }

This is ...

The best content for your career. Discover unlimited learning on demand for around $1/day.