Recommendations for a first GHC API project

In general terms, I want to broaden my Haskell knowledge by learning the GHC API to better understand the compilation pipeline. Ultimately, I intend to contribute to projects like Liquid Haskell or HLS, and compile my own projects to WASM. This knowledge could be an asset for me to work on a GSoC proposal in case Haskell is selected this year.

The GHC API documentation is quite dense. I figured I could start by developing a simple application to get to grips with the basics, but don´t know what kind of application would be a good target. I’ll appreciate any ideas on a simple project I could accomplish by myself, and any up-to-date references that could be of help (blog posts or tutorials).

3 Likes

I guess the answer ultimately depends on how much/which parts of the GHC API you want to work with. I have used it for developing a small HLS plugin, implementing a new “code action”, and I can recommend doing so. It is a project that is small enough to be manageable, but significant enough to be useful. How you will be using the API will depend on the needs of the plugin of course. In my case it was mostly fiddling with the AST, but you can pick a suitable plugin idea if you have some specific parts of the API you are interested in.

6 Likes

Thanks for the suggestion. Can you share a link to your plugin?

Here is the link to the source. I have also documented the process in this blog post. It has been a few years since then, so I expect some inner workings of HLS to have changed. The fundamentals shouldn’t have changed much though, so I hope the post would still be of some use.

This is exactly the kind of lead I was looking for; incidentally, my motivations are basically the same as stated in your blog post. By the way, I find the import list of the plugin source astounding. I wonder how folks manage the complexity of such an abundance of dependencies, but guess that’s another topic.

If someone else would come forward, I still want to known about similar simple projects (or ideas) that depend on the GHC API at some level. Also (or alternatively), what was your experience when using it for the first time?

For future reference in the forum, here is a plugin tutorial from the HLS documentation.

I did this work as part of an internship, so I was fortunate enough to have a supervisor that guided me through the process. Even if you go into this on your own, being able to ask your questions when you have them is very helpful. Therefore, I would highly advise you to join the GHC chatroom.

Regarding the learning materials, you more or less have to dive into the GHC source code. The surface exposed by the GHC API is mostly incidental (though there is a recent initiative to improve the situation), so reading the Haddock documentation is usually not enough. However, the source-level documentation is fantastic: the code is documented extensively and the “notes” convention allows you to find related pieces of documentation as well. For higher-level overviews of the various parts of GHC, the GHC wiki/commentary is also quite helpful.

I don’t know if the situation has improved since then, but at the time the HLS plugin tutorial was vastly outdated, and it was partly the motivation for my blog post. However, as with my suggestion above, the HLS chatroom is quite active and therefore is a good place to ask any questions you might have.

2 Likes