TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Writing a simple evaluator and type-checker in Haskell

126 pointsby bor0about 6 years ago

6 comments

brmgbabout 6 years ago
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 未加载
platzabout 6 years ago
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>
chriswarboabout 6 years ago
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;
danidiazabout 6 years ago
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>
kornishabout 6 years ago
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 未加载
herbsteinabout 6 years ago
This basically summarized the first half of the programming languages course I took. Nicely done