I am learning F # and I believe that I am writing something that works, but which I do not quite understand. Here is an example
let processArgs args = match args with | null | [||] -> [fun() -> getCredentials(); home 20; mentions 20; messages 20] | [|"-h"|] | [|"-?"|] -> [showHelp] | [|"-reset"|] -> [clearAllSettings] | _ -> [fun() -> printfn "%s" (String.Join(" ", args))] [<EntryPoint>] let main (args:string[]) = try let actions = processArgs args List.iter (fun action -> action()) actions 0 finally Console.ResetColor() Console.CursorVisible <- true
The methods getCredentials, home, mentions, messages, showHelp and clearAllSettings are all simple functions and do what you expect. (Yes, this is a Twitter client, isn't this a new Hello World demo?)
Line:
[fun() -> getCredentials(); home 20; mentions 20; messages 20]
works as i want. It calls getCredentials, then home, then mentions, then messages
From my point of view, the semicolon acts as a separator of statements. I have not seen this before. Is that what is going on here?
Is there a more idiomatic way to write this (in other words, will a seasoned F # programmer laugh on the floor when he sees this?)
Additional Information: My initial intention was to have a list of actions, and then add actions when I discover the parameters. In C #, I usually did this with List <Action> (). The semicolon surprised me, because initially I tried to write it like this:
[getCredentials; home 20; mentions 20; messages 20]
But he did not like the compiler.