Variable

From HaskellWiki
Jump to: navigation, search

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 pi to stand for 3.14159..., or X^2 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.