p.93 "In F#, we can read command line arguments using the standard .NET Environment.GetCommandLineArgs method."
If C# developers are the primary audience then those familiar with console applications would be accustomed to
[pre]
static void Main(string[] args)
[/pre]
so it may be a good time to mention EntryPointAttribute.
The F# 1.9.6.16 Draft Language Specification:
13.1.2 Explicit Main Entry Point
http://research.microsoft.com/en-us/um/cambridge/projects/fsharp/manual/spec.html#_Toc234058195
e.g.
[pre]
let writeGraph file =
let lines = List.of_seq (File.ReadAllLines file)
let data = processLines lines
let total = float (countSum data)
let calcPrc num = int ((float num)/total * 100.0)
for (lbl, num) in data do
Console.WriteLine ("{0,-18} - {1,8} ({2}%)", lbl, num, calcPrc( num ))
let execute (args:string[]) =
if args.Length > 0 && (File.Exists args.[0]) then
writeGraph args.[0]
0 // Return 0. This indicates success.
else
printfn "Please specify a path to a valid data CSV file."
-1
// "Debug->Start Without Debugging" keeps console window open after termination.
// "Debug->Start Debugging" does not.
type ConsoleWindowUtil =
// So under DEBUG throw in an additional stop - otherwise bypass method
[<Conditional("DEBUG")>]
static member keepOpen =
printfn "Press any key to continue . . ."
ignore (Console.ReadKey())
[<EntryPoint>]
let main args =
let exitCode = execute args
ConsoleWindowUtil.keepOpen
exitCode
(* Set file path in Visual Studio Solution Explorer Project Properties
-> Debug(Configuration: All Configurations): Start Options: Command Line Arguments
CAVEAT: EntryPoint has to be the "last declaration in the last file in the compilation sequence".
Otherwise - error FS0191: A function labelled with the 'EntryPointAttribute' attribute
must be the last declaration in the last file in the compilation sequence.
*)
[/pre]
Also note that Listing 4.5 (p.90) references "C:Ch03data.csv" even though the discussion has moved to Chapter 4.