How to name Haskell variables which in physics are

2019-02-16 16:57发布

Variable names in haskell need to be in small case, but

How to declare variables in .hs file, if we want to store g = 9.8 and G = 6.67300 × 10-11 (in following scenario) ?

Conventionally Physicists mention :

(1) Acceleration due to gravity on earth

g = 9.8 m/sec^2

(2) Universal Gravitational constant

G = 6.67300 × 10-11 m3 kg-1 s-2

3条回答
不美不萌又怎样
2楼-- · 2019-02-16 17:15

I would simply use g and _G. I think the underscore isn't too distracting.

查看更多
Animai°情兽
3楼-- · 2019-02-16 17:16

You could give them meaningful names. Just because mathematicians and physicists historically liked to use inscrutable symbols with no way of interpreting them other than rote memorisation doesn't mean you have to. We're typing now, not writing long-hand, so defining equations in terms of earthGravity and gravitationalConstant isn't so much harder to write than in terms of g and G, and it's a hell of a lot easier to read!

Or, you could designate that all identifiers prefixed with something like c represent standard well known constants, and use cg and cG.

查看更多
一夜七次
4楼-- · 2019-02-16 17:19

You will just have to come up with another name. The distinction between names starting with upper- and lowercase letters is part of the syntax.

While this may be unfortunate in your case, it's a design trade-off. In order to simplify differentiating between different things (e.g. between variables and constructors), identifiers starting with lowercase letters and ones starting with uppercase letters are fundamentally different.

查看更多
登录 后发表回答