Printing out Haskell's evaluation (rewriting) steps for educational/learning purposes. Is it possible?

核能气质少年 提交于 2019-12-03 05:49:36
Bergi

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!

There is a tool called Lambda bubble pop where you can click on the expression to see how the expression is getting reduced. Note that the tool only supports Integers and Lists as of now, but nevertheless is a good educational tool.

Snapshot of the tool in action:

This is a much-requested and highly useful feature — which, as best as I know, is not available anywhere. :-(

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!