Infinite main loop in F#
design-patterns, f#, functional-programming
Solution
Typing in browser, thus may contain errors:
let rec main() =
let c = System.Console.ReadKey()
if c.Key = System.ConsoleKey.Q then () // TODO: cleanup and exit
else
// TODO: do something in main
main()
Problem
A usual pattern for CLI application is to run in infinite loop, until user types some quit command. Like, in C language: ``` while(1){ scanf("%c", &op); ... else if(op == "q") break; } ``` What would be the pattern for such console application in F# (tried to use tail recursrion, but failed)?