F#: More thoughts on the forward & application operators

I’ve been spending a bit of time reading through the Fake source code to try and understand how it works and one of the things which I quite like about it is the way the authors have made use of different F# operators to make expressions easier to read by reducing the number of brackets that need to be written and reordering the functions/values depending on the particular context.

The log function is of type ‘string -> unit’ and the sprintf call helps create that string. Without the application operator we would have to put in extra parentheses:

log (sprintf "Deleting %s" file.FullName)

The code also makes use of the forward operator which I think panders more to the object oriented style of programming whereby you have have some data/object and then apply a method/function to that. I find that code written in this way reads more intuitively to me at the moment.

Lookup on object of indeterminate type based on information prior to this program point. A type annotation may be needed prior to this program point to constrain the type of the object. This may allow the lookup to be resolved

In this case what we’re being told is that the compiler is unable to work out the type of ‘file’ in the function being passed to ‘Seq.iter’. We can fix this by specifically stating its type:

It works but it seems to miss the point of getting the F# compiler to infer which types you’re talking about - the forward operator simplifies the code a lot. I also think the code is more readable having ‘files’ at the beginning as it seems more obvious that the function is being applied to the sequence of files when written this way.