Chapter 6. .NET Programming

The .NET platform is a general-purpose programming platform that can do more than just object-oriented or functional programming. This chapter will cover some additional concepts available when using .NET that will offer advantages when you put them to use in your F# code.

In this chapter, you will learn how to use interfaces to build better abstractions, enums, and structs, which can help performance, and how to use F#’s object expressions for boosting programmer productivity.

The .NET Platform

Let’s begin our look at .NET-specific concepts by examining the runtime on which .NET applications execute. This will help you understand how to take full advantage of the platform by seeing the features F# gets for free.

The CLI

The foundation of the .NET platform is the CLI, or Common Language Infrastructure. This is a specification for a runtime system that actually runs your F# code. The F# compiler produces a binary file called an assembly, which is composed of a high-level assembly language called MSIL or Microsoft Intermediate Language.

An implementation of the CLI compiles this MSIL to machine code at runtime to execute the code faster than if it were just interpreted. The compilation happens “just-in-time” as the code is needed, or JIT.

Code that is compiled to MSIL and executed through the JITter is referred to as managed code, as opposed to unmanaged code, which is simply raw machine code (typically from programs written in C or C++).

There are several benefits ...

Get Programming F# now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.