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

编程入门 行业动态 更新时间:2024-10-28 10:22:01
本文介绍了在 HLint 的上下文中 eta reduce 是什么意思的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在看教程 haskell/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 是什么意思

本文发布于:2023-10-08 14:13:25,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1472866.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:文中   HLint   reduce   eta

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!