
So you want to write a type checker (2014) - ChickeNES
http://languagengine.co/blog/so-you-want-to-write-a-type-checker/
======
danblick
People sometimes ask on HN about good books on implementing programming
languages.

One of the best textbooks I know on type theory is also a pretty good book for
getting a programming language up and running: Types and Programming Languages
by Ben Pierce.

[https://mitpress.mit.edu/books/types-and-programming-
languag...](https://mitpress.mit.edu/books/types-and-programming-languages)

The book starts off implementing the untyped lambda calculus and then adds
more and more interesting kinds of types. There's a tarball somewhere on the
course website that has all the code from the book, and it's kind of fun to
play with all the systems it covers.

~~~
psygnisfive
I'd also recommend Practical Foundations for Programming Languages (PFPL). And
a bunch of other things, which I outlined here:

So You Want To Learn Type Theory
([http://purelytheoretical.com/sywtltt.html](http://purelytheoretical.com/sywtltt.html))

------
amelius
Perhaps I don't want to just type-check, but I want to do type-inference as
well.

~~~
labbekak
I recommend the paper "Complete and Easy Bidirectional Typechecking for
Higher-Rank Polymorphism" by Dunfield and Krishnaswami. It describes an easy
to implement algorithm for type inference for higher ranked types that can
subsume Hindley-Milner.

Implementation in Haskell:
[https://github.com/ollef/Bidirectional](https://github.com/ollef/Bidirectional)

Implementation in Javascript/Typescript (by me):
[https://github.com/atennapel/bidirectional.js](https://github.com/atennapel/bidirectional.js)

~~~
cf
Your comment expanded out is what I had hoped that blogpost would have been.
Thank you for posting this. It's hard to overstate how much easier
bidirectional typechecking is compared to other approaches.

My favorite starting point is actually Dunfield's lecture notes on
bidirectional type checking, [https://people.mpi-
sws.org/~joshua/bitype.pdf](https://people.mpi-sws.org/~joshua/bitype.pdf)

The paper you mentioned is great at showing the approach scales well to giving
you all the fancy features you might want that are in modern languages.

------
gingerb
I use types.js
([https://www.npmjs.com/package/types.js](https://www.npmjs.com/package/types.js))
dynamic type checker already for years in production without any issues. I
simply don't want yet another JS syntax or transpiler only for type checking
like Typescript, Flow etc.. For me that's way over the top.

~~~
seanmcdirmid
Typescript was designed in such a way that the transpired mostly merely
removes type annotations from the TS file to the JS one. They also went with a
loose optional structural type system to be as non invasive as possible
(ironically enough, it can be less strict than a nominal dynamic type system).

------
dchasson
alright hacker news, how did you know what I've been doing for 16 hours?

~~~
AceJohnny2
Having a good weekend? :)

------
alkonaut
Venn diagram of people who are interested in type theory, and people who like
Javascript...

    
    
        OO

~~~
dunstad
You might want to give this a look:
[https://github.com/Microsoft/TypeScript](https://github.com/Microsoft/TypeScript)

~~~
alkonaut
My point exactly. If people who liked type systems could stand to use the JS
type system (and I only barely managed to write type system without scare
quotes), we wouldn't have TypeScript. Or Cofeescript. Or Purescript. Or Elm.
Or Fable. Or Flow. Or even ES6.

~~~
Cyph0n
Why is everyone forgetting Scala.js?

~~~
fasquoika
Because if they listed every language that compiled to JS the actual point of
their comment would get buried?

~~~
Cyph0n
The focus of the original comment was on compile-to-JS languages with
strong(er) type systems. Scala.js should be at the top of that list.

Try again.

------
igravious
From (2014) people!

~~~
psygnisfive
It was also front page on HN at the beginning of 2015 ;)

