Creating Local Variables Using Let Bindings

Now that you’ve learned how to create new top-level variables and functions, it’s time to look at how to build more complex functions. In this section, you’ll learn how to build larger and more complex functions by building up intermediate computations using let bindings.

Let bindings allow you to give a name to some particular expression in your program. Let’s start with an example. We’ll rewrite our makeGreeting function from before to use an intermediate value. If you still have access to your previous file where you defined makeGreeting, feel free to re-use it. Otherwise, create a new Main.hs with a function named makeGreeting with the following definition:

 module​ ​Main​ ​where
 
 makeGreeting ...

Get Effective Haskell now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.