Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Strange FSharpLint warning

Tags:

f#

I am trying to reimplement the List.distinct function:

let inline distinct list =
    let folder curr = function
        | [] -> [curr]
        | l -> if List.contains curr l then l else curr :: l
    List.foldBack folder list []
    ^^^^^^^^^^^^^^^^^^^^^^^^^^^^

I got a lint warning that says

List.foldBack f x [] might be able to be refactored into x

However that doesn't make much sense to me as this leads me to return the original list without performing the distinct logic.

Is this a bug of FSharpLint?

like image 347
rexcfnghk Avatar asked Nov 09 '16 09:11

rexcfnghk


1 Answers

Apparently that's a wrong rule. Take a look at this excerpt from FSharpLint's default configuration:

List.fold f x [] ===> x
Array.fold f x [||] ===> x
List.foldBack f x [] ===> x
Array.foldBack f x [||] ===> x

It's the same for fold and foldback here, so it doesn't follow the differences in signatures between the two.

The order of initial state and collection arguments should be flipped, see the "mnemonic" approach used in foldback definition.

like image 147
scrwtp Avatar answered Oct 30 '22 05:10

scrwtp