简体   繁体   English

如何将Haskell中的lambda项的求值强制为强范式

[英]How to force the evaluation of a lambda term in haskell to the strong normal form

I was wondering if it is possible to turn off lazy evaluation in Haskell; 我想知道是否有可能在Haskell中关闭惰性评估。
I would like to force the evaluation of a lambda term to the strong normal form. 我想将lambda项的评估强制为强范式。

For instance: I would like \\x -> (\\y -> y) x 1 to be reduced to \\x -> x 1 例如:我希望将\\x -> (\\y -> y) x 1减少为\\x -> x 1

Thanks in advance. 提前致谢。

You can't do it. 你做不到 The reason is that Haskell isn't supposed to perform lambda term reductions. 原因是Haskell不应该执行lambda词条缩减。 Haskell evaluates programs (lambda terms) to values. Haskell将程序(lambda术语) 评估为值。 One possibility how to do this would be to really perform lambda term reductions, but this would be quite inefficient. 这样做的一种可能性是真正执行lambda项减少,但是效率很低。 So Haskell compilers use many sophisticated techniques such as graph reduction instead. 因此,Haskell编译器改用了许多复杂的技术,例如图形约简。 Therefore you can't observe differences such as (\\x -> x) y vs y during the evaluation process - there are no actual lambda terms to be observed. 因此,在评估过程中您无法观察到(\\x -> x) y vs y差异-没有实际的lambda项可观察。

Note that GHC has NFData type class which allows to evaluate terms to their normal forms using rnf - r -educe to n -ormal f -orm (but only products or coproducts, it still doesn't evaluate terms under lambdas, as @JakeMcArthur pointed out). 请注意,GHC具有NFData类型类,该类允许使用rnf - r-归纳为n-正规f -orm来评估其正常形式的术语(但仅乘积或副产物,它仍然不评估lambdas下的术语,如@JakeMcArthur所指出的那样)出)。 However, this doesn't give you access to the normal form expressed as a lambda term. 但是,这不能让您访问用lambda术语表示的普通形式。 It only tells Haskell to perform this evaluation during the computation. 它仅告诉Haskell在计算过程中执行此评估。

This question may be tackled by supercompilers. 超级编译器可以解决这个问题。 Right now, there is none that works really well with the current ghc and current packages. 目前,没有任何工具可以与当前的ghc和当前的软件包真正兼容。

There exists an older implementation of a supercompiler: http://community.haskell.org/~ndm/supero/ 有一个较旧的超级编译器实现: http : //community.haskell.org/~ndm/supero/

I you are interested in some newer considerations, this may be of interest: http://pure.ltu.se/portal/files/2231262/nwpt08-scp.pdf 如果您对一些较新的注意事项感兴趣,则可能会感兴趣: http : //pure.ltu.se/portal/files/2231262/nwpt08-scp.pdf

However, I cannot either propose a proper solution. 但是,我不能提出适当的解决方案。

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

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