You are previewing Programming F# 3.0, 2nd Edition.

Programming F# 3.0, 2nd Edition

Cover of Programming F# 3.0, 2nd Edition by Chris Smith Published by O'Reilly Media, Inc.
  1. Programming F# 3.0
  2. Preface
    1. Introducing F#
    2. Who This Book Is For
    3. What You Need to Get Going
    4. How the Book Is Organized
      1. Part I
      2. Part II
      3. Part III
    5. Part IV
    6. Conventions Used in This Book
    7. Using Code Examples
    8. Safari® Books Online
    9. I’d Like to Hear from You
    10. Acknowledgments
  3. I. Multiparadigm Programming
    1. 1. Introduction to F#
      1. Getting to Know F#
      2. Visual Studio 11
      3. F# Interactive
      4. Managing F# Source Files
    2. 2. Fundamentals
      1. Primitive Types
      2. Comparison and Equality
      3. Functions
      4. Core Types
      5. Organizing F# Code
    3. 3. Functional Programming
      1. Understanding Functions
      2. Pattern Matching
      3. Discriminated Unions
      4. Records
      5. Lazy Evaluation
      6. Sequences
      7. Queries
    4. 4. Imperative Programming
      1. Understanding Memory in .NET
      2. Changing Values
      3. Units of Measure
      4. Arrays
      5. Mutable Collection Types
      6. Looping Constructs
      7. Exceptions
    5. 5. Object-Oriented Programming
      1. Programming with Objects
      2. Understanding System.Object
      3. Understanding Classes
      4. Methods and Properties
      5. Inheritance
    6. 6. .NET Programming
      1. The .NET Platform
      2. Interfaces
      3. Object Expressions
      4. Extension Methods
      5. Extending Modules
      6. Enumerations
      7. Structs
  4. II. Programming F#
    1. 7. Applied Functional Programming
      1. Active Patterns
      2. Using Modules
      3. Mastering Lists
      4. Tail Recursion
      5. Programming with Functions
      6. Functional Patterns
      7. Functional Data Structures
    2. 8. Applied Object-Oriented Programming
      1. Operators
      2. Generic Type Constraints
      3. Delegates and Events
      4. Events
    3. 9. Asynchronous and Parallel Programming
      1. Working with Threads
      2. Asynchronous Programming
      3. Asynchronous Workflows
      4. Parallel Programming
      5. Task Parallel Library
    4. 10. Scripting
      1. F# Script Files
      2. Directives
      3. F# Script Recipes
    5. 11. Data Processing
      1. Indexing
      2. Querying
  5. III. Extending the F# Language
    1. 12. Reflection
      1. Attributes
      2. Type Reflection
      3. Dynamic Instantiation
      4. Using Reflection
    2. 13. Computation Expressions
      1. Toward Computation Expressions
      2. Computation Expression Builders
      3. Custom Computation Expression Builders
    3. 14. Quotations
      1. Quotation Basics
      2. Generating Quotation Expressions
    4. 15. Type Providers
      1. Typed Data Versus Typed Languages
      2. Type Providers
  6. IV. Appendixes
    1. A. Overview of .NET Libraries
      1. Visualization
      2. Data Processing
      3. Storing Data
    2. B. F# Interop
      1. .NET Interop
      2. Unmanaged Interop
  7. Index
  8. About the Author
  9. Colophon
  10. Copyright

Appendix B. F# Interop

This book shows how F# can be a great language for helping you to be more productive, while seamlessly integrating with the existing .NET stack. Although it is true that F# is a great language, the word seamlessly may need to be qualified.

The dominant languages used in .NET today are C# and Visual Basic .NET (VB.NET), and although in F# you can write and call into object-oriented assemblies to interact with C# and VB.NET code, some concepts may get lost in translation.

This appendix is focused on how to ease interop with F#. By the end of this appendix, you’ll be able to identify problem areas when doing multilanguage programming. In addition, you’ll be able to have your F# interoperate with unmanaged (native) code as well by using Platform Invoke and COM.


Although F# allows you to work with both C# and Visual Basic .NET, in this appendix, I’m just going to refer to C# for convenience. Whenever you see the term C#, you can replace it with the phrase C# or Visual Basic .NET depending on your preference.

.NET Interop

The key to interoperation between .NET languages is to make sure that the types and methods in the public surface area of a class library are available to all languages consuming the code. Intuitively, if a library exposes constructs that are not native to the consuming language, things can look a little strange. Or, even worse, the library exposes different idioms for the concepts in both languages.

Nullable Types

Nullable types are for unfortunate ...

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