The Author Online Book Forums are Moving

The Author Online Book Forums will soon redirect to Manning's liveBook and liveVideo. All book forum content will migrate to liveBook's discussion forum and all video forum content will migrate to liveVideo. Log in to liveBook or liveVideo with your Manning credentials to join the discussion!

Thank you for your engagement in the AoF over the years! We look forward to offering you a more enhanced forum experience.

tempusfugit (144) [Avatar] Offline
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
static void Main(string[] args)
so it may be a good time to mention EntryPointAttribute.

The F# Draft Language Specification:
13.1.2 Explicit “Main” Entry Point


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.
printfn "Please specify a path to a valid data CSV file."

// "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
static member keepOpen =
printfn "Press any key to continue . . ."
ignore (Console.ReadKey())

let main args =
let exitCode = execute args

(* 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.

Also note that Listing 4.5 (p.90) references "C:Ch03data.csv" even though the discussion has moved to Chapter 4.
Tomas Petricek (160) [Avatar] Offline
Re: 4.3 Creating a Console Application (Suggestion)
thanks for the feedback - I added a brief note about the attribute, so that the readers know this is another option.