Java F# 中的下划线等效项?

Java underscore equivalent in F#?

在 Java 中可以写 1_000_000 而不是 1000000 以获得更好的可读性。 F# 中有等效的东西吗?

此问题已在 feature request page 上提出,此更改请求的当前状态为 "planned""approved in principle".
所以它可能会在下一个版本中实现。

您可以在 github page for F#:

上找到有关此请求的更多信息(如有关此功能的摘要、动机和建议的实施细节)

Summary

Allow underscores between any digits in numeric literals. This feature enables you, for example, to separate groups of digits in numeric literals, which can improve the readability of your code.

For instance, if your code contains numbers with many digits, you can use an underscore character to separate digits in groups of three, similar to how you would use a punctuation mark like a comma, or a space, as a separator.

Motivation

This is a popular feature in other languages. Some other languages with a similar feature:

  • Perl
  • Ruby
  • Java 7
  • C++11 (use single quote)

just to name a few...

Detailed design

You can place underscores only between digits. You cannot place underscores in the following places:

  • At the beginning or end of a number
  • Adjacent to a decimal point in a floating point literal
  • Prior to an F or L or other suffix
  • In positions where a string of digits is expected