Variable

From HaskellWiki
Revision as of 00:15, 11 October 2006 by BrettGiles (talk | contribs) (HaWiki conversion)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)
Jump to navigation Jump to search
The printable version is no longer supported and may have rendering errors. Please update your browser bookmarks and please use the default browser print function instead.

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..., or to represent the formula to compute to test for goodness of fit. These values do not generally change in the middle of performing a mathematical calculation or proof.

The operator = is used to assign a value to a variable, e.g. phi = 1.618. The scope of such variables can be controlled by using let or where clauses.

Another sense in which "variable" is used in Haskell is as formal parameters to a function. For example:

add x y = x + y

x and y are formal parameters for the add function. This corresponds to the notion of "variable" in the lambda calculus.