When do you put double semicolons in F#?

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!

Leave a Comment

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)