The wikibooks Haskell page on variables and functions notes the following:
Note
The let keyword (a word with a special meaning) lets us define variables directly at the GHCi prompt without a source file. This looks like:
Prelude> let area = pi * 5 ^ 2Although sometimes convenient, assigning variables entirely in GHCi this way is impractical for any complex tasks. We will usually want to use saved source files.
but I can just do area = pi * 5 ^ 2 at the prompt and skip the let. I've also seen this use of let at the prompt in Learn You a Haskell. Why would I use the let, is there something important about it that I'm missing?
GHCi evaluates the expression (the whole line) as soon as enter is pressed, and the expression itself cannot be spaned over several lines (to make an expression in GHCi span over multiple lines
:{and:}can be used).In Haskell, a
letexpression should be followed byin. But in GHCi the expression is interpreted in theIOmonad, and aletbinding with no accompanyinginstatement can be just be followed by an empty line.Since GHC
8.0.1it is possible to bind values and functions to names withoutletstatement.Important difference, however, between these two types of binding and a third type, the monadic bind, is that the monadic bind a <- exp is strict, so exp is evaluated immediately, while with the
letform or direct equality form exp would not be evaluated immediately.