An imperative language would probably pass through the list once, make
a copy, and then return it. It would then pass through the list another two
times, making copies each time, and return the result.
In a lazy language, calling doubleMe on a list without forcing it to show
you the result just makes the program tell you, “Yeah yeah, I’ll do it later!”
Once you want to see the result, the first doubleMe calls the second one and
says it wants the result immediately. Then the second one says the same
thing to the third one, and the third one reluctantly gives back a doubled
1, which is 2. The second doubleMe receives that and returns 4 to the first
one. The first doubleMe then doubles this result and tells you that the first ele-
ment in the final resulting list is 8. Because of Haskell’s laziness, the doubleMe
calls pass through the list just once, and only when you really need that to
happen.
Haskell is statically typed. This means that
when you compile your program, the compiler
knows which piece of code is a number, which
is a string, and so on. Static typing means that a
lot of possible errors can be caught at compile
time. If you try to add together a number and
a string, for example, the compiler will whine
at you.
Haskell uses a very good type system that
has type inference. This means that you don’t
need to explicitly label every piece of code with a type, because Haskell’s
type system can intelligently figure it out. For example, if you say a = 5 + 4,
you don’t need to tell Haskell that a is a number—it can figure that out by
itself. Type inference makes it easier for you to write code that’s more gen-
eral. If you write a function that takes two parameters and adds them to-
gether, but you don’t explicitly state their type, the function will work on
any two parameters that act like numbers.
Haskell is elegant and concise. Because it uses a lot of high-level con-
cepts, Haskell programs are usually shorter than their imperative equiva-
lents. Shorter programs are easier to maintain and have fewer bugs.
Haskell was made by some really smart guys (with PhDs). Work on
Haskell began in 1987 when a committee of researchers got together to
design a kick-ass language. The Haskell Report, which defines a stable ver-
sion of the language, was published in 1999.
What You Need to Dive In
In short, to get started with Haskell, you need a text editor and a Haskell
compiler. You probably already have your favorite text editor installed, so we
won’t waste time on that. The most popular Haskell compiler is the Glasgow
Haskell Compiler (GHC), which we will be using throughout this book.
The best way to get what you need is to download the Haskell Platform.
The Haskell Platform includes not only the GHC compiler but also a bunch
of useful Haskell libraries! To get the Haskell Platform for your system, go to
Introduction xvii