One of the projects I’m working on needed arguments passed in from the command line. Coming from the C# world I'm use to getting the arguments from the main function.
static void Main(string[] args)
{
}
Since F# doesn't have an explicitly defined entry point I had to do some searching. I came across a module in OCaml called Arg which worked. The F# document can be found here. Robert at strangelights.com has a great post on the usage of it.
For those of you who just want an array the following will work.
let cmdArgs = System.Environment.GetCommandLineArgs()
Don't forget if you’re using .Net 1.x you'll need to convert the array to a compatible one.
let compatibleCmdArgs = Compatibility.CompatArray.to_array(cmdArgs)
Easier yet, instead of calling GetCommandLineArgs() we can use the argv value in the module Microsoft.FSharp.MLLib.Sys which will return a compatible array for us.
let cmdArgs = Sys.argv