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

后端 未结 3 1983
自闭症患者
自闭症患者 2020-12-30 00:54

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

3条回答
  •  -上瘾入骨i
    2020-12-30 01:42

    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!

提交回复
热议问题