在 HLint 的上下文中 eta reduce 是什么意思 [英] What does eta reduce mean in the context of HLint
问题描述
我正在看教程 http://haskell.org/haskellwiki/How_to_write_a_Haskell_program
import System.Environment
main :: IO ()
main = getArgs >>= print . haqify . head
haqify s = "Haq! " ++ s
在HLint下运行这个程序时出现以下错误;
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! " ++ )
有人能解释一下在这种情况下Eta Reduce"究竟是什么意思?
Can someone shed some light on what exactly "Eta Reduce" means in this context?
推荐答案
Eta 减少正在转向 x ->f x
到 f
只要 f
没有 x
的自由出现.
Eta reduction is turning x -> f x
into f
as long as f
doesn't have a free occurence of x
.
要检查它们是否相同,请将它们应用于某个值 y
:
To check that they're the same, apply them to some value y
:
(x -> f x) y === f' y -- (where f' is obtained from f by substituting all x's by y)
=== f y -- since f has no free occurrences of x
您对 haqify
的定义被视为 s ->Haq!" ++ s
,它是 s -> 的语法糖(++) 哈克!"s
.这反过来又可以简化为 (++) "Haq! "
,或者等效地,使用运算符的节符号,("Haq!" ++)
.
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! " ++)
.
这篇关于在 HLint 的上下文中 eta reduce 是什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!