TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Writing a simple evaluator and type-checker in Haskell

126 点作者 bor0大约 6 年前

6 条评论

brmgb大约 6 年前
If you are interested in the subject, The Implementation of Functional Programming Languages by Simon Peyton Jones is actually freely available on his Microsoft Research page : <a href="https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;research&#x2F;publication&#x2F;the-implementation-of-functional-programming-languages&#x2F;" rel="nofollow">https:&#x2F;&#x2F;www.microsoft.com&#x2F;en-us&#x2F;research&#x2F;publication&#x2F;the-imp...</a><p>The book is really great. It starts with a very interesting explanation of lambda calculus and how high-level functional programming language can be tied to it. Chapters 8 and 9 were written by Peter Hancock and cover step by step how to write a polymorphic type-checker (the examples are in Miranda but it&#x27;s not far from Haskell).<p>For a 1987 book, it all aged very well.
评论 #19402365 未加载
评论 #19401991 未加载
platz大约 6 年前
Inference is a little more involved once you add lambda abstraction and function application.<p>Recommended:<p>Christoph Hegemann: type inference from scratch: <a href="https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ytPAlhnAKro" rel="nofollow">https:&#x2F;&#x2F;www.youtube.com&#x2F;watch?v=ytPAlhnAKro</a>
chriswarbo大约 6 年前
Their grammar&#x27;s a bit off, since they have:<p><pre><code> &lt;bool&gt; ::= T | F | IsZero &lt;num&gt; &lt;num&gt; ::= O &lt;arith&gt; ::= Succ &lt;num&gt; | Pred &lt;num&gt; </code></pre> Here `&lt;num&gt;` can only ever be `O`, so that&#x27;s the only valid argument for `IsZero`, `Succ` and `Pred`. I would put `O` into `&lt;arith&gt;`, get rid of `&lt;num&gt;` and replace all references to it with `&lt;arith&gt;`.<p>That doesn&#x27;t affect the actual implementation, since (as they say right after) &quot;For simplicity, we merge all them together in a single Term.&quot;
danidiaz大约 6 年前
Another educational (but more sophisticated) evaluator &#x2F; typechecker in Haskell is described in &quot;Stitch: The Sound Type-Indexed Type Checker&quot; <a href="https:&#x2F;&#x2F;cs.brynmawr.edu&#x2F;~rae&#x2F;papers&#x2F;2018&#x2F;stitch&#x2F;stitch.pdf" rel="nofollow">https:&#x2F;&#x2F;cs.brynmawr.edu&#x2F;~rae&#x2F;papers&#x2F;2018&#x2F;stitch&#x2F;stitch.pdf</a>
kornish大约 6 年前
Isn’t this a reskin of Stephen Diehl’s earlier set of blog posts? Or is this a common PL example? <a href="http:&#x2F;&#x2F;dev.stephendiehl.com&#x2F;fun&#x2F;004_type_systems.html" rel="nofollow">http:&#x2F;&#x2F;dev.stephendiehl.com&#x2F;fun&#x2F;004_type_systems.html</a>
评论 #19401840 未加载
herbstein大约 6 年前
This basically summarized the first half of the programming languages course I took. Nicely done