You need to stop thinking in terms of a book and start thinking in terms of
People read books when they have decided to invest time reading them - in which case paying for a book is usually no problem. What’s needed is something to take people from “I’m mildly curious about Haskell” to “I am going to learn Haskell.”
Also: a lot of text in the wikibook is useless or worse. Eg this gem
Of course, you can use functions that you have already defined to define new functions, just like you can use the predefined functions like addition (+)
or multiplication (*)
(operators are defined as functions in Haskell). For example, to calculate the area of a square, we can reuse our function that calculates the area of a rectangle:
This is so shallow and pointless that the average reader’s brain may well reject it and they will waste time rereading and looking for a deeper meaning. (That’s what mine just did.) Programmers expect functions to be able to call functions, they don’t need telling that they can, gosh, call the factorial function they’ve just written. You just need
This is how you define and call a function in Haskell:
product a b = a * b
product 2 * 7 => 14
This is called currying:
m42 = product 42
m42 10 => 420
m42 2 => 84
This is “point free” style
m7 = (*7)
m7 3 => 21
Haskell is an expression based language, ie a function is a chain of value calculations leading to a final value that gets returned. That means every step must have a value. Eg both branches of an if statement “return” a value:
factorial x = if x==1 then 1 else factorial x * factorial (x-1)
You may use less if’s than you expect in Haskell thanks to alternatives like pattern matching on values
factorial 1 = 1
factorial x = x * factorial (x-1)
and guards:
…Obvious example omitted. Then show :t and writing a type signature:
This is a type signature. Haskell can generate them for you, but you will often want the control of writing them yourself:
product Num a => a → a → a
mul42 Num a=> a → a
Num a => constrains the arguments to belong to things that implement operations like + and *
a → a → a means takes a Num, then another Num, then returns a Num.
Then you move on to tuples and lists, which is when you also bring in where, passing functions around, and more pattern matching. That fast.
The point is to get people interested. And the way to get programmers interested - especially the ones willing to try a new language - is to show them cool code as quickly as possible. Again, as quickly as possible. Not to bore them to death telling them that functions can call functions. It’s coding language speed dating. The goal should be to intrigue the other person, not to tell them your life history in minute detail.