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
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...,...
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.
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.
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!
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With