是否可以使用 WinHugs 打印 Haskell 中的所有约简?
我编写了以下函数..并使用 WinHugs 执行
teneven = [x | x <- [1..10], even x]
我的输出:
Main> teneven
[2,4,6,8,10] :: [Integer]
(63 reductions, 102 cells)
是否有办法打印所有缩减..以便我可以了解 WinHugs 内部发生的核心评估?
I have written the following function.. and executed using WinHugs
teneven = [x | x <- [1..10], even x]
My output:
Main> teneven
[2,4,6,8,10] :: [Integer]
(63 reductions, 102 cells)
is there anyway to print all the reductions.. so I can learn the core evaluation happening inside WinHugs?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
一些想法:
调试命令行选项(您可以在 Hugs 中使用
:set +d
设置)提供了丰富的信息,但非常冗长,并且不会向您显示 Haskell 语法的减少。尝试Haskell Tracer。 我只是在一个简单的程序上尝试了一下,效果非常酷。 不过,我不在 Windows 上,我不知道让它运行起来有多困难。 这可能相当困难,这很遗憾,因为它很酷并且本质上就是您想要的。 如果您确实运行了它,您可以从 Hat 获取类似以下信息:
<前><代码>主要 = {IO}
十偶 = [2,4,6,8,10]
_foldr (\..) [1,2,3,4,5,6,7,8, ...] [] = [2,4,6,8,10]
(\..) 1 [2,4,6,8,10] = [2,4,6,8,10]
(\..) 2 [4,6,8,10] = [2,4,6,8,10]
(\..) 3 [4,6,8,10] = [4,6,8,10]
(\..) 4 [6,8,10] = [4,6,8,10]
(\..) 5 [6,8,10] = [6,8,10]
(\..) 6 [8,10] = [6,8,10]
(\..) 7 [8,10] = [8,10]
(\..) 8 [10] = [8,10]
(\..) 9 [10] = [10]
(\..) 10 [] = [10]
那里的 lambda 是
偶数
。 此外,如果您愿意,Hat 还可以跟踪foldr
的调用以及其他内部调用; 默认情况下,它不会这样做。Some ideas:
The debug command-line option (which you can set with
:set +d
in Hugs) is informative, but is very verbose and does not show you the reductions in Haskell syntax.Try Hat - the Haskell Tracer. I just tried it on a simple program and it's pretty cool. I'm not on Windows, though, and I don't know how difficult it would be to get it running. It's likely fairly difficult, which is a shame since it's cool and essentially what you want. If you do get it running, you can get something like this information from Hat:
The lambda there is
even
. Also, if you want, Hat can trace into calls offoldr
and other internal calls; by default, it doesn't do that.这里有一些使用 Debug.Trace 和 Hugs.Observe 的示例。
希望这可以帮助您了解如何使用 WinHungs 打印所有缩减。
Here you have a few examples of the use of Debug.Trace and Hugs.Observe.
Hope this helps you to figure out how to print all reductions using WinHungs.
相信我,你不想走这条路。
每个特定情况下使用的缩减集(和顺序)将取决于特定的语言实现(hugs 可以以一种方式实现,ghci - 以其他方式实现,jhc - 以另一种方式实现,等等)。
更好地阅读一些关于实现函数式语言的编译器/解释器/虚拟机的一般方法的内容 - 例如 SECD 机等。
几个链接:
Believe me, you dont want to go this way.
Set (and order) of reductions used in each particular case would depend on particular language implementation (hugs could do it one way, ghci - in other way, jhc - in yet another, etc).
Better read something about general ways to implement compiler/interpreter/virual machine for functional language - like SECD machine, etc.
Several links: