Search code examples
haskellsemantics

How to name the "=" of a Haskell expression?


let a = 3

Does it mean:

  • "Construct an object named a" or
  • "bind value 3 to object a" or
  • "assign a value to variable a"?

If everything in Haskell is a function, so can I say here a is also a function? But functions can be called, how can I call "a"?


Solution

  • let a=3
    

    "Construct an object named a"

    No, this is not common terminology in Haskell.

    "bind value 3 to object a"

    This is closer. One could simply say "bind value 3 to name (or variable, or identifier) a". There are no "objects" in Haskell.

    "assign a value to variable a"

    No, "assignment" usually implies that one can mutate the value of a variable, when this is not the case in pure functional programming.

    Personally, I'd just read let a = 3 as "define a as 3". In Haskell, most of the time, we reason about the values of variables, disregarding when exactly such values are constructed / allocated / garbage collected and how exactly the values are represented in memory. So, we usually avoid to think about "how" operationally a program is executed, focusing more on "what" is the result, and whether it is the intended one ("denotationally").

    Of course, after we get the intended result, we do start caring about the performance of our programs. For that, we need to have at least a rough idea about the "how" the program is executed, its memory allocations, etc.