Share via


Set.difference<'T> Function (F#)

Returns a new set with the elements of the second set removed from the first.

Namespace/Module Path: Microsoft.FSharp.Collections.Set

Assembly: FSharp.Core (in FSharp.Core.dll)

// Signature:
Set.difference : Set<'T> -> Set<'T> -> Set<'T> (requires comparison)

// Usage:
Set.difference set1 set2

Parameters

  • set1
    Type: Set<'T>

    The first input set.

  • set2
    Type: Set<'T>

    The set whose elements will be removed from set1.

Return Value

The set with the elements of set2 removed from set1.

Remarks

This function is named Difference in compiled assemblies. If you are accessing the function from a language other than F#, or through reflection, use this name.

Example

The following code illustrates the use of the Set.difference function.

let set1 = Set.ofList [ 1 .. 3 ]
let set2 = Set.ofList [ 2 .. 6 ]
let setDiff = Set.difference set2 set1
printfn "Set.difference [2 .. 6] [1 .. 3] yields %A" setDiff

Output

Set.difference [2 .. 6] [1 .. 3] yields set [4; 5; 6]

Platforms

Windows 7, Windows Vista SP2, Windows XP SP3, Windows XP x64 SP2, Windows Server 2008 R2, Windows Server 2008 SP2, Windows Server 2003 SP2

Version Information

F# Runtime

Supported in: 2.0, 4.0

Silverlight

Supported in: 3

See Also

Reference

Collections.Set Module (F#)

Microsoft.FSharp.Collections Namespace (F#)