Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to define a constant literal in F#

Tags:

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

like image 950
Alan Wayne Avatar asked Oct 15 '25 08:10

Alan Wayne


1 Answers

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
like image 79
Brian Berns Avatar answered Oct 17 '25 14:10

Brian Berns



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!