mercredi 26 juillet 2017

How does the compiler treat a boolean argument that has been partially applied?

I read an interesting article about boolean arguments of functions:

http://ift.tt/2gTFD9A

The author argues that in many cases it is better to split a function that has a boolean argument into two. This is because the use of boolean parameters increases the cyclomatic complexity of the code.

So consider the following simple function:

let fbool (b: bool) (x: int) =
    if b then x
    else -x

Next, define a function defined from partial application, as follows:

let ftrue x = fbool true x

or equivalently

let ftrue = fbool true

Is the F# compiler smart enough to do what the author recommends, that is, is ftrue as defined above a function that does not contain an if statement and therefore does not contribute to cyclomatic complexity? Or does it contain an if statement but happens to always choose the true branch?

Aucun commentaire:

Enregistrer un commentaire