简体   繁体   English

Haskell实现没有堆栈?

[英]Haskell implemented without a stack?

from How does a stackless language work? 来自无堆栈语言如何工作?

Haskell (as commonly implemented) does not have a call stack; 
evaluation is based on graph reduction.

Really? 真? That's interesting, because while I've never experienced it myself, I've read that if you don't use the strict versions of the fold functions and then force the evaluation of an infinite fold you get a stack overflow. 这很有意思,因为虽然我自己从未体验过它,但我已经读过,如果你不使用折叠函数的严格版本然后强制评估无限折叠,你会得到堆栈溢出。 Surely that indicates the presence of a stack. 当然,这表明存在堆栈。 Can anyone clarify? 任何人都可以澄清吗?

I'm not by any means an expert on this, but I think the answer you quoted is not entirely accurate. 我绝对不是这方面的专家,但我认为你引用的答案并不完全准确。 Haskell doesn't have the straightforward kind of stack most imperative languages have, where you can trace a path of calls through a program. Haskell没有大多数命令式语言的直接堆栈类型,您可以通过程序跟踪调用路径。 Because of its laziness, evaluation is based on graph reduction, which you can read about here , but calls are still eventually placed in a stack. 由于它的懒惰,评估是基于图形缩减,您可以在这里阅读,但调用仍然最终放在堆栈中。 According to this page, "The “stack“ in GHC's execution engine bears little resemblance to the lexical call stack." 根据这个页面,GHC的执行引擎中的“堆栈”与词汇调用栈几乎没有相似之处。 So yes, there's a stack, but it's very different from one you would find in an imperative language, and it's created using graph reduction. 所以,是的,有一个堆栈,但它与您在命令式语言中找到的堆栈非常不同,并且它是使用图形缩减创建的。

Haskell is not "stackless" or anything like it. Haskell不是“无堆栈”或类似的东西。 Code generated from Haskell source still has some kind of symbols and execution shows some stack traces but they're very loosely related to source code. 从Haskell源生成的代码仍然具有某种符号,执行显示一些堆栈跟踪,但它们与源代码的关系非常松散。 Here's some information about attempts of simplifying debugging/tracing/profiling: 以下是有关简化调试/跟踪/分析的尝试的一些信息:

http://www.haskell.org/wikiupload/9/9f/HIW2011-Talk-Marlow.pdf http://www.haskell.org/wikiupload/9/9f/HIW2011-Talk-Marlow.pdf

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

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