出于教育/学习目的,打印出Haskell的评估(重写)步骤。可能吗? [英] Printing out Haskell's evaluation (rewriting) steps for educational/learning purposes. Is it possible?

查看:85
本文介绍了出于教育/学习目的,打印出Haskell的评估(重写)步骤。可能吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我通过使用书中的示例来描述这个问题。



在西蒙·汤普森(Simon Thompson)的书 HASKELL函数式编程的技巧(第82页)中(参见下图)显示了 fac 4 的评估步骤。



问题:



是否可以使用某些工具或某些 Haskell调试器来写出GHCi在评估 fac 4



最好采用人类可读的格式,用于教育和学习。



对每个评估步骤都有一些自动的解释也是很好的,例如在重写步骤中使用了哪个方程式。



我的主要目的是加深了解我运行简单的教育性Haskell示例程序(例如 fac )。



有没有办法做到这一点?如果是,怎么办?





解决方案

是和否。我还没有看到一种可以在课本中进行逐行评估的工具-主要是因为Haskell程序不会对计算机进行重写。


但是,有一个工具可以逐步可视化Haskell的实际评估策略:


来源:项目网站的示例部分。您应该看看所有这些!


I describe this question by using an example from a book.

In Simon Thompson's book "HASKELL the craft of functional programming" on page 82 (see images below) are shown the evaluation steps for fac 4.

QUESTION:

Is it possible to use some tool or some "Haskell debugger" that would write out the evaluation steps that GHCi uses when it would evaluate the value of fac 4 ?

Preferably in a human readable format, for educational and learning purposes.

It would be also good to have some automatic explanation for each evaluation step, for example which equation was used in the rewriting step.

My main purpose is to gain a deeper understanding of how the rewriting steps are carried out when I run simple educational Haskell example programs (like fac).

Is there a way to do this ? If yes, how ?

解决方案

Yes and No. I haven't seen a tool yet that does this line-by-line evaluation that is depicted in your textbook - mostly because a Haskell programm does no "rewriting" of expressions.

However, there is a tool that does visualize Haskell's actual evaluation strategy, step by step: ghc-vis. Instead of just evaluating the result and displaying it on the console like ghci does, it displays a graphical representation of the unevaluated result - and you can force the evaluation of it thunk by thunk, until you arrive at the primitive values and structures.

As an example of what it can do, here's the evaluation until the third list member of the infinite fibonacci sequence:

Source: examples section of the project website. You should have a look at all of them!

这篇关于出于教育/学习目的,打印出Haskell的评估(重写)步骤。可能吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆