[Haskell-beginners] variables in haskell

Matthew J. Williams matthewjwilliams1 at googlemail.com
Wed Oct 15 01:52:29 EDT 2008

>>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?

         My recollection of 'final' in 'Java' is a little vague, 
nevertheless, in 'c/c++' the const keyword indicates that the 
associated function argument must be 'treated' as a constant. I am 
not convinced that the idea of a constant value is not being 
honored  in this situation. The function definition is after all a 
'pattern' (if I may be permitted to use the term in its most general sense):

         int f (const int x) {
                 return (x+1);

would be equivalent to the following:

         let f x = x+1

         In 'c/c++' a global constant would have very similar 
properties, in fact, exactly similar in so far as the 'immutability' 
of the value is concerned.

         Matthew J. Williams 

More information about the Beginners mailing list