gpt4 book ai didi

haskell - 在 HLint 的上下文中,eta reduce 是什么意思

转载 作者:行者123 更新时间:2023-12-04 01:17:39 31 4
gpt4 key购买 nike

我在看教程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 下运行此程序时,会出现以下错误;
./Haq.hs:11:1: Warning: Eta reduce
Found:
haqify s = "Haq! " ++ s
Why not:
haqify = ("Haq! " ++ )

有人可以解释一下究竟是什么 “Eta减少”在这种情况下意味着什么?

最佳答案

Eta减少正在转向\x -> f x进入 f只要f没有 x 的免费出现.

要检查它们是否相同,请将它们应用于某个值 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 -> (++) "Haq! " s 的语法糖.这反过来又可以 eta 减少到 (++) "Haq! " ,或等效地,对运算符使用节符号 ("Haq! " ++) .

关于haskell - 在 HLint 的上下文中,eta reduce 是什么意思,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5793843/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com