问题描述
我正在阅读教程
import System.Environment
main :: IO()
main = getArgs>> = print。 haqify。头部
haqify s =Haq!++ s
这个程序在HLint下出现以下错误;
./ Haq.hs:11:1:警告:Eta减少
p>
找到:
haqify s =Haq!++ s
为什么不是:
haqify =(Haq!++)
有人可以从中了解Eta Reduce的含义吗?
Eta裁减正在转向\ x - >>
转换为解决方案fx
f
,只要f
没有<$ $的空闲出现次数C $ C> X 。
要检查它们是否相同,请将它们应用于某些值
y
:(\ x - > fx)y === f'y - (其中f'是通过用y代替所有x得到的) )
=== fy - 因为f没有任何空闲的x
您的定义
haqify
被视为\s - > Haq!++ s
,它是\s->的语法糖。 (++)Haq!s
。反过来,可以将eta简化为(++)Haq!
,或者等价地,对运算符使用分段符号,(Haq !++)
。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
:(\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
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减少了什么意思的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!