Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

When do you put double semicolons in F#?

Tags:

f#

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?

like image 237
rsteckly Avatar asked Apr 19 '10 16:04

rsteckly


People also ask

What does double semicolon mean?

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.

Can I use two semicolons in one sentence?

Yes, semicolons can be used to connect three, or more, related independent clauses.

What is double semicolon in shell script?

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.


1 Answers

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!

like image 139
Tomas Petricek Avatar answered Sep 23 '22 14:09

Tomas Petricek