I'm looking at the tutorial http://haskell.org/haskellwiki/How_to_write_a_Haskell_program
import System.Environment
main :: IO ()
main = getArgs >>= print . haqify . head
haqify s = "Haq! " ++ s
When running this program under HLint it gives the following error;
./Haq.hs:11:1: Warning: Eta reduce
Found:
haqify s = "Haq! " ++ s
Why not:
haqify = ("Haq! " ++ )
Can someone shed some light on what exactly "Eta Reduce" means in this context?
Eta reduction is turning
\x -> f x
intof
as long asf
doesn't have a free occurence ofx
.To check that they're the same, apply them to some value
y
:Your definition of
haqify
is seen as\s -> "Haq! " ++ s
, which is syntactic sugar for\s -> (++) "Haq! " s
. That, in turn can be eta-reduced to(++) "Haq! "
, or equivalently, using section notation for operators,("Haq! " ++)
.Well, eta reduction is (one way) to make point-free functions, and usually means that you can remove the last parameter of a function if it appears at the end on both sides of an expression.
can be converted to
However, in this case it is slightly more complicated, since there is the syntactic sugar of two-parameter operator
(++)
on the rhs, which is type[a] -> [a] -> [a]
. However, you can convert this to a more standard function:Because
(++)
is an operator, there are other possibilities:That is, the parens convert this into a one-parameter function which applies
"Haq!" ++
to its argument.From lambda calculus, we define eta conversion as the equality:
See Barendregt, H. P. The Lambda Calculus: Its Syntax and Semantics, 1984.
In the Haskell context, see the definition on the Haskell wiki,
and