Getting Started with Haskell

Haskell lives at the intersection between practical applied languages and research languages created to push the boundaries of what’s possible to do in a programming language. The expressiveness and flexibility that makes Haskell useful for computer science research turns out to also be incredibly useful for the working engineer who wants to build reliable and maintainable systems. That’s why you’ll find it used in everything from web applications to data pipelines to compilers and configuration management tools.

The Haskell motto avoid success at all costs is a reminder that programming in Haskell sometimes means trading away immediate familiarity or comfort for power, flexibility, and correctness. Avoiding short-term success and doing what’s right is the Haskell path to long-term success. This trade-off means that things that you might take for granted in other languages work a little bit differently in Haskell. Haskell is no harder to learn than any other language, but for experienced developers, the challenge is in unlearning old practices and preconceptions.

One of the ways Haskell is different is that it’s a pure functional language. Haskell developers like to throw the words pure and purity around frequently, but you won’t always find an exact definition of what it means. For our purposes, we can think of purity like this: in a Haskell program, all values are immutable, and all functions have to be free of any side effects. That means we can’t ever modify in place or change the value of variables, we can’t modify any global state, and we can’t arbitrarily do things like read from files on disk, access the network, or print something to the screen. At first, this might seem like an onerous set of restrictions, but as you’ll see starting in Chapter 7 , Haskell gives you a rich set of tools and alternative patterns so that you can write the same sorts of programs that you would write in an impure language.

Another way that Haskell differs from many other popular languages is in the power and expressiveness of its type system. You’ll start to learn more about how to make use of Haskell’s type system starting in Chapter 4 . In the mean time, we’ll take advantage of Haskell’s sophisticated type inference which will allow us to start getting familiar with the language without worrying too much about types.

Finally, Haskell is a lazy language. That means Haskell has the powerful ability to avoid running parts of our program until it’s sure that we will need the results. This can let us write programs in ways that feel more natural but might have significant negative performance costs in a strict language. You’ll have an opportunity to start learning about laziness starting in the next chapter .

For now, we’ll focus on getting familiar with the basic syntax of Haskell. In this chapter you’ll start learning Haskell from the ground up by getting a handle on foundational concepts like defining variables, creating and calling functions, and working with lists. A lot of this will feel familiar, but working through it carefully will ensure that you don’t get tripped up by subtle but fundamental features of Haskell as we get deeper into the language in later chapters.