When do you put double semicolons in F#?

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

    I suspect that you have seen F# code written when #light syntax wasn't enabled by default (#light syntax is on by default for the May 2009 CTP and later ones as well as for Visual Studio 2010) and then ;; means the end of a function declaration.

    So what is #light syntax? It comes with the #light declaration:

    The #light declaration makes whitespace significant. Allowing the developer to omit certain keywords such as in, ;, ;;, begin, and end.

    Here's a code written without #light syntax:

    let halfWay a b =
      let dif =  b - a in
      let mid = dif / 2 in
      mid + a;;
    

    and becomes with light syntax:

    #light
    let halfWay a b =
      let dif =  b - a
      let mid = dif / 2
      mid + a
    

    As said you can omit the #light declaration now (which should be the case if you're on a recent CTP or Visual Studio 2010).

    See also this thread if you want know more on the #light syntax: F# - Should I learn with or without #light?

提交回复
热议问题