Breaking Changes in F# 3.0

This topic describes breaking changes in the 3.0 version of the F# compiler and language for the Visual Studio 2012 release.

List of Breaking Changes

The following table lists breaking changes in F# 3.0.

Area of breaking change

Description

Indentation

Some incorrect indentation that was erroneously accepted by previous versions of the F# compiler produces a compilation error in the current version. For a complete description of indentation rules, see Code Formatting Guidelines (F#).

Quotations, methods, and properties of structures that are local variables

It’s now an error to call a property or method of a structure in a quotation when that structure is a local variable. Previous versions of F# allowed this behavior.

[<Struct>]
type S =
   member this.Valid = true
let check () =
    let mutable s = S()
    <@ s.Valid @> // Error

To work around this requirement, create a copy of the local variable, as the following example shows:

let check () =
    let s = S()
    <@ 
        let s = s
        s.Valid 
    @>

Equality for improper nulls

In previous versions, you could compare null values by using the = operator regardless of whether they were proper or improper values of a type. A proper null is a null value that the type allows; an improper null isn’t a valid value for the type. The current behavior is to throw a NullReferenceException when you attempt use the = operator to compare improper nulls, as the following code shows.

let a : int ref = Unchecked.defaultof<_>
let main() =
    printfn "%A" (a = a)
main()

Comments and strings

In previous versions, a closing comment token *) in a triple-quoted string (a string that uses """) was parsed as a part of a string. In the current version, that token is parsed as a closing comment character. Therefore, the following code, which previously was accepted, will produce an error in the current version:

(* """ *)
Let x = 1

For more information, see Strings (F#).

Properties that have different getter and setter types.

In earlier versions of F#, the F# compiler incorrectly allowed getter and setter methods to have types that didn’t match (for example, a getter of type int and a setter of type string). In F# 3.0, the compiler reports such a declaration as an error.