如何命名Haskell变量,这在物理上是大写的 [英] How to name Haskell variables which in physics are uppercase

查看:174
本文介绍了如何命名Haskell变量,这在物理上是大写的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

haskell中的变量名称需要小写,但是

如何在.hs文件中声明变量,如果我们要存储 g = 9.8和 G = 6.67300×10-11(在以下情况下)?

传统物理学家提到:



(1)由于地球上的重力而产生的加速度

g = 9.8 m / sec ^ 2
(2)万有引力常数 b
$ b G = 6.67300×10-11 m3 kg -1 s-2

解决方案

您只需要提出另一个名称。以大写和小写字母开头的名称之间的区别是语法的一部分。



虽然这可能是不幸的在你的情况下,这是一个设计权衡。为了简化不同事物之间的区分(例如变量和构造函数之间的区别),以小写字母开头并以大写字母开头的标识符根本不同。


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

解决方案

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.

这篇关于如何命名Haskell变量,这在物理上是大写的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆