Reviving "Typing Haskell in Haskell"

Hi all,

I’ve been studying THIH by Mark P Jones recently (Typing Haskell in Haskell); it’s a good, executable introduction* to the mechanics of type inference in our favorite language.

There is a copy of the original repository on Hackage (uploaded by Gwern in 2008 , thih: Typing Haskell In Haskell ), but until today it did not have a backup maintainer.
I think it would be valuable to save this project from bitrot and perhaps feature it in a more central place in our ecosystem. It certainly deserves better Haddock documentation and more readable tests.

I did the minimal amout of work to make it build under a recent GHC (9.0.2) : GitHub - ocramz/thih: typing haskell in haskell and my plan is to add docstrings.

I’m currently waiting to hear back from Prof. Jones, fingers crossed this project will have his “blessing”.


* Not the only one though : “Algorithm W step by step” (Algorithm-W-Step-By-Step/AlgorithmW.pdf at master · wh5a/Algorithm-W-Step-By-Step · GitHub) is equally awesome albeit slightly less general.

10 Likes

I think it would be great to have a simple implementation of the type system to do research on. I wanted to see what it would take to implement MLF and also found THIH, but I bounced off.

There’s also this: Typing Haskell with an Attribute Grammar.

4 Likes

I made a markdown version of this in 2014 Typing Haskell in Haskell · GitHub

I also copied the thih source and iterated on it to produce Duet GitHub - chrisdone/duet: A tiny language, a subset of Haskell aimed at aiding teachers teach Haskell which is a Haskell subset. The thing missing from THIH which I had to figure out was converting type class contexts into actual dictionaries. That’s a whole extra stage. Plus kind checking for data declarations and type checking of instances and stuff like that.

(I’ve since done a complete ground up implementation of a compiler (https://inflex.io/) with type classes based on this experience but the architecture is quite different (Inflex - Google Slides), but it’s not open source yet.)

5 Likes