This is a stupid question. I've been reading a couple books on F# and can't find anything that explains when you put ;; after a statement, nor can I find a pattern in the reading. When do you end a statement with double semi-colons?
A "double semicolon" does not have any special meaning in c. The second semicolon simply terminates an empty statement. So you can simply remove it.
Yes, semicolons can be used to connect three, or more, related independent clauses.
The double semicolon is also useful as it leaves no ambiguity in the code. It is required as it is used at the end of each clause as required by the bash syntax in order to parse the command correctly. It is only used in case constructs to indicate that the end of an alternative.
In the non-interactive F# code that's not supposed to be compatible with OCaml, you shouldn't need to ever need double semicolon. In the OCaml compatible mode, you would use it at the end of a top-level function declaration (In the recent versions, you can switch to this mode by using files with .ml
extension or by adding #light "off"
to the top).
If you're using the command-line fsi.exe
tool or F# Interactive in Visual Studio then you'd use ;;
to end the current input for F#.
When I'm posting code samples here at StackOverflow (and in the code samples from my book), I use ;;
in the listing when I also want to show the result of evaluating the expression in F# interactive:
Listing from F# interactive
> "Hello" + " world!";; val it : string = "Hello world!" > 1 + 2;; val it : int = 3
Standard F# source code
let n = 1 + 2 printf "Hello world!"
Sometimes it is also useful to show the output as part of the listing, so I find this notation quite useful, but I never explained it anywhere, so it's great that you asked!
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With