简体   繁体   English

Haskell - Eta 减少和 Eta 扩展

[英]Haskell - Eta reduction and Eta expansion

I've been studying functional program optimization, and have been digging into the GHC source.一直在研究函数式程序优化,一直在挖掘GHC源码。 I (mostly) understand what eta reduction and eta expansion are.我(大部分)理解 eta 缩减和 eta 扩展是什么。 Eta reduction only removes redundant lambdas: Eta 减少仅删除多余的 lambda:

\x -> abs x
=>
abs

Eta expansion is the opposite of eta reduction and does things like this (correct me if I'm incorrect): Eta 展开与 eta 减少相反,并执行以下操作(如果我不正确,请纠正我):

abs
=>
\x -> abs x
-----------------------------------------------
foo = abs
=>
foo x = abs x
-----------------------------------------------
foo = bar 100
bar x y = x + y
=>
foo y = bar 10 y
bar x y = x + y
-----------------------------------------------
etc...

What I don't get is how they don't get in each other's way and send the compiler into an infinite loop.我不明白的是它们如何不妨碍彼此并将编译器发送到无限循环中。 For example, first, a value is eta expanded, and then it is eta reduced, and so on.例如,首先对一个值进行 eta 扩展,然后将其进行 eta 缩减,依此类推。 So, how do the two optimizations not get in each other's way?那么,这两种优化如何不妨碍对方呢?

I think I found an answer.我想我找到了答案。 I found a thesis from a contributor to GHC (don't remember what it was called), and in it, it mentioned that GHC doesn't do eta reduction.我从 GHC 的一位贡献者那里找到了一篇论文(不记得它叫什么了),其中提到 GHC 不做 eta 减少。 Instead, it does eta expansion, and beta reduction (IIRC);相反,它进行 eta 扩展和 beta 减少(IIRC); Beta reduction does most of the job. Beta 减少完成了大部分工作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM