简体   繁体   中英

How to define a constant literal in F#

In C#, I do this:

 public const double PAPER_SIZE_WIDTH = 8.5 * 96; 

What is the best way to define this global constant in F#?

This fails:

  [<Literal>]
  let PaperSizeWidth = 8.5*96.0  

Error: This is not a valid constant expression

TIA

Arithmetic is not yet supported for numeric literals in F#. Instead, you have to provide the final value explicitly:

[<Literal>]
let PaperSizeWidth = 816.0

However, every value is immutable by default in F#, so this might be good enough, depending on your needs:

let PaperSizeWidth = 8.5 * 96.0

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM