Header menu logo G-Research F# Analyzers

VirtualCall Analyzer


Certain Seq operations should be avoided when the input collection type is known and has a specific module counter-part. This can avoid a type cast or a virtual call at runtime and the specific collection implementation is more performant. Example: Use Set.fold rather than Seq.fold when the argument is a set.

let f () =
    let mySet = set [1..10]
    Seq.fold (+) 0 mySet // should warn


Use the Set counterpart

let f () =
    let mySet = set [1..10]
    Set.fold (+) 0 mySet
val f: unit -> int
val mySet: Set<int>
val set: elements: 'T seq -> Set<'T> (requires comparison)
module Seq from Microsoft.FSharp.Collections
val fold<'T,'State> : folder: ('State -> 'T -> 'State) -> state: 'State -> source: 'T seq -> 'State
Multiple items
module Set from Microsoft.FSharp.Collections

type Set<'T (requires comparison)> = interface IReadOnlyCollection<'T> interface IStructuralEquatable interface IComparable interface IEnumerable interface IEnumerable<'T> interface ICollection<'T> new: elements: 'T seq -> Set<'T> member Add: value: 'T -> Set<'T> member Contains: value: 'T -> bool override Equals: obj -> bool ...

new: elements: 'T seq -> Set<'T>
val fold<'T,'State (requires comparison)> : folder: ('State -> 'T -> 'State) -> state: 'State -> set: Set<'T> -> 'State (requires comparison)

Type something to start searching.