你什么时候在 F# 中放双分号? [英] When do you put double semicolons in F#?

查看:20
本文介绍了你什么时候在 F# 中放双分号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是一个愚蠢的问题.我一直在阅读有关 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?

推荐答案

在不应该与 OCaml 兼容的非交互式 F# 代码中,您不应该需要双分号.在 OCaml 兼容模式下,您将在顶级函数声明的末尾使用它(在最近的版本中,您可以通过使用带有 .ml 扩展名的文件或通过添加 #light "off" 到顶部).

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).

如果您在 Visual Studio 中使用命令行 fsi.exe 工具或 F# Interactive,那么您将使用 ;; 结束 F# 的当前输入.

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#.

当我在 StackOverflow 上发布代码示例时(以及在 我的书 中的代码示例中),我在列表中使用 ;; 当我还想显示在 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:

  • 从 F# 交互式列表

> "Hello" + " world!";;
val it : string = "Hello world!"
> 1 + 2;;
val it : int = 3

  • 标准 F# 源代码

    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!

    这篇关于你什么时候在 F# 中放双分号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

    查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆