PostfixGenericsAnalyzer
Problem
Generally, the .NET style should be used for generics. However, it is suggested to use the postfix syntax for arrays, lists, sequences, options, value options, and reference cells in the F# style guide.
// Triggers analyzer
let a: string[] = Array.empty
let b: list<string> = List.empty
let c: seq<string> = Seq.empty
let d: option<string> = None
let e: voption<string> = ValueNone
let f: ref<string> = ref ""
Fix
The postfix
syntax is preferred:
let a: string array = Array.empty
let b: string list = List.empty
let c: string seq = Seq.empty
let d: string option = None
let e: string voption = ValueNone
let f: string ref = ref ""
val a: string array
Multiple items
val string: value: 'T -> string
--------------------
type string = System.String
val string: value: 'T -> string
--------------------
type string = System.String
module Array
from Microsoft.FSharp.Collections
val empty<'T> : 'T array
val b: string list
type 'T list = List<'T>
Multiple items
module List from Microsoft.FSharp.Collections
--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
module List from Microsoft.FSharp.Collections
--------------------
type List<'T> = | op_Nil | op_ColonColon of Head: 'T * Tail: 'T list interface IReadOnlyList<'T> interface IReadOnlyCollection<'T> interface IEnumerable interface IEnumerable<'T> member GetReverseIndex: rank: int * offset: int -> int member GetSlice: startIndex: int option * endIndex: int option -> 'T list static member Cons: head: 'T * tail: 'T list -> 'T list member Head: 'T member IsEmpty: bool member Item: index: int -> 'T with get ...
val empty<'T> : 'T list
val c: string seq
Multiple items
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
val seq: sequence: 'T seq -> 'T seq
--------------------
type 'T seq = System.Collections.Generic.IEnumerable<'T>
module Seq
from Microsoft.FSharp.Collections
val empty<'T> : 'T seq
val d: string option
type 'T option = Option<'T>
union case Option.None: Option<'T>
val e: string voption
type 'T voption = ValueOption<'T>
union case ValueOption.ValueNone: ValueOption<'T>
val f: string ref
Multiple items
val ref: value: 'T -> 'T ref
--------------------
type 'T ref = Ref<'T>
val ref: value: 'T -> 'T ref
--------------------
type 'T ref = Ref<'T>
type 'T array = 'T array