Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to name Haskell variables which in physics are uppercase

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

like image 602
Optimight Avatar asked Jun 27 '12 04:06

Optimight


People also ask

What is a variable in Haskell?

In Haskell, a variable is a name for some valid expression. The word "variable" as applied to Haskell variables is misleading, since a given variable's value never varies during a program's runtime. Instead, the concept is much closer to the mathematical sense of the word, where one might use to stand for 3.14159...,...

How do you create a new type in Haskell?

But one of the best parts about Haskell is that it is easy to build our own types. We do this using the “data” keyword, and then giving a type name (which must begin with a capital letter): data FightMove = … We then describe our type with a series of type constructors, separated by the | character.

Why is Haskell so different from other programming languages?

The reason for this is that haskell's abstractions are different from those of the mainstream imperative languages, and the mapping isn't 1-1. So for a particular 'C' feature, there may be 3 or 4 haskell features which achieve similar effects, and the correct choice depends on the detailed context.

Can We have multiple constructors in Haskell?

In Java, we can have multiple constructors that each take a different set of parameters but all produce the same type of object. However, no matter what, the resulting object in Java will always have the same instance variables with the same types. This is not the case in Haskell!


1 Answers

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.

like image 198
Tikhon Jelvis Avatar answered Oct 23 '22 18:10

Tikhon Jelvis