When do you put double semicolons in F#?

前端 未结 9 1195
孤独总比滥情好
孤独总比滥情好 2021-01-01 09:39

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

9条回答
  •  轻奢々
    轻奢々 (楼主)
    2021-01-01 10:12

    The double semi-colon is used to mark the end of a block of code that is ready for evaluation in F# interactive when you are typing directly into the interactive session. For example, when using it as a calculator.

    This is rarely seen in F# because you typically write code into a script file, highlight it and use ALT+ENTER to have it evaluated, with Visual Studio effectively injecting the ;; at the end for you.

    OCaml is the same.

    Literature often quotes code written as it would appear if it had been typed into an interactive session because this is a clear way to convey not only the code but also its inferred type. For example:

    > [1; 2; 3];;
    val it : int list = [1; 2; 3]
    

    This means that you type the expression [1; 2; 3] into the interactive session followed by the ;; denoting the end of a block of code that is ready to be evaluated interactively and the compiler replies with val it : int list = [1; 2; 3] describing that the expression evaluated to a value of the type int list.

提交回复
热议问题