When do you put double semicolons in F#?

前端 未结 9 1232
孤独总比滥情好
孤独总比滥情好 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:15

    There is no purpose for double semi-colons (outside of F# interactive). The semi-colon, according to MSDN:

    • Separates expressions (used mostly in verbose syntax).
    • Separates elements of a list.
    • Separates fields of a record.

    Therefore, in the first instance, ;; would be separating the expression before the first semi-colon from the empty expression after it but before the second semi-colon, and separating that empty expression from whatever came after the second semi-colon (just as in, say C# or C++).

    In the instance of the list, I suspect you'd get an error for defining an empty list element.

    With regards to the record, I suspect it would be similar to separating expressions, with the empty space between the semi-colons effectively being ignored.

    F# interactive executes the entered F# on seeing a double semi-colon.

    [Updated to cover F# interactive - courtesy of mfeingold)

提交回复
热议问题