A satisfying Haskell setup

Since I am used to the hot reload capabilities of the node.js (nodemon) and the modern JavaScript frontend ecosystem, I was very pleased to discover GHCid, built to improve the UX of GHCi, the REPL of GHC.

My old Haskell workflow was having a tmux window split into two panes, one with Vim, one with GHCi loaded (with different modules). When making relevant changes, I jumped to the GHCi window and typed :r. I have no issues with this workflow, but one jump less is more… civilized.

Now I have a similar approach. Assume a Haskell project located in SomeProject.hs (including the main function) and just write,

ghcid --command 'ghci SomeFile.hs' --test :main

Every saved change in your editor will immediately force a type check and run the main function. If the project contains errors, you see errors with the usual GHCi view. And if no errors exist, your project runs. This is especially suited for projects involving some kind of visual interface.

Recently I was told by a colleague, that Stack includes a flag for re-compiling (even re-running) on changes, however, for some reason, you must also press a key (any key). Therefore I think the GHCid procedure is more pleasant. You can combine this with Stack projects as well,

ghcid --command 'stack ghci app/Main.hs' --test :main

It’s not naive efficiency measured in time that please me the most – rather, vaguely put, the user experience and if you will, making it more ergonomic.

This is a demo of an less advanced use, only using GHCid for instant GHCi type checking.