How to name Haskell variables which in physics are uppercase

女生的网名这么多〃 提交于 2019-12-01 03:55:25

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.

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.

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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!