Types of the form a -> b
really just mean
function taking a value of type
a
and returning a value of typeb
And from there on it's just repeated application for larger (multiple arrows) types, much like 1 + 2 + 3 + 4
isn't all that different from 1 + 2
.
One potential stumbling stone is that either of these values can be a function itself. Your interpretation of the curried type is correct, but note that add x
is a valid expression on its own, and gives another function (one which only needs one argument before returning an int
).
As for the second type: Just like int -> (int -> int)
is the type
take an
int
and return a functionint -> int
"
the type (int -> int) -> int
means
take a function
int -> int
and return anint
It's a higher-order function, a function which accepts a function as argument.
One not-entirely-useless example would be the function sum0To100 f = sum (map f [0 .. 100])
(or equivalent functions for any other range). For example, sum0To100 fib
is the sum of the first 100 Fibonacci numbers.