I’m reading A Gentle Introduction to Haskell. Paraphrasing part of the book where it is discussing the usefulness of infix operators in the context of partial application.
(+) = \x y -> x+y
essentially coerces an infix operator into an equivalent functional value and it is handy when passing an infix operator as an argument to a function, as in map (+) [1,2,3]
(the reader should verify that this returns a list of functions!).
-
First, I don’t see that/how
map (+) [1,2,3]
returns a list of functions. My guess (which I guess is wrong) is that it will add 1, 2, & 3. -
Second, I don’t know how to confirm it returns a list of functions. I tried it in GHCi and got an error
• No instance for (Show (Integer -> Integer))
arising from a use of ‘print’
(maybe you haven't applied a function to enough arguments?)
• In a stmt of an interactive GHCi command: print it
Which indicates it is waiting for another argument. So I tried
> x = map (+) [1,2,3]
> x 2
But that is also an error
• Couldn't match expected type ‘Integer -> t’
with actual type ‘[Integer -> Integer]’
• The function ‘x’ is applied to one argument,
but its type ‘[Integer -> Integer]’ has none
In the expression: x 2
In an equation for ‘it’: it = x 2
• Relevant bindings include it :: t (bound at <interactive>:5:1)