[Haskell-beginners] variables in haskell

Tillmann Rendel rendel at daimi.au.dk
Tue Oct 14 04:03:43 EDT 2008

Matthew J. Williams wrote:
> Hello listers, would one be correct in thinking that 'bound variables' 
> such as those used in haskell were in fact constants?

I think I see what you mean, but it is not entirely correct. A constant 
is something which has the same value at all times. For example, 
top-level declarations in most languages, including Haskell, can be seen 
as constants:

   foo = "hello world" -- this foo will always mean "hello world"

If the value associated with a name changes from time to time, then we 
call that name a variable.

   bar foo = ... -- foo will mean something else everytime bar is called

The behaviour of Haskell variables is similiar to "constant variables" 
or "final variables" in other languages, e.g. in Java

   public int bar(final int foo) {

Similiar to the Haskell version, in this Java code, foo will be 
something different for each call of bar, but it will not change during 
one execution of bar. Your wouldn't call foo a constant here, would you?


More information about the Beginners mailing list