I have a large Haskell file (around 3000 lines) with many imports (around 150). I'm trying to break it up to smaller files to -- among other things -- improve build parallelism and therefore build times.
The simplest and most naive way of doing this could be to duplicate the whole import header among all the new broken-up files. Everything would be working, except there would be a lot of repetition in those (maybe 5-10) new files and maintenance burden would become considerably worse, i.e. when one of the imports need to be changed it is now in 10 places instead of one.
The more advanced option would be to create a CommonImports.hs file, where I import everything needed, then re-export ala
module CommonImports (module X) where import Foo as X
. This would work for the most part, except there is about 50 imports that are qualified. As far as I'm aware currently there is no way to re-export/re-import keeping the original qualifications in place. This could be done with a lot of refactoring where I remove all qualifications and resolve any name conflicts.There is a 3rd option: use the C preprocessor's
#include
feature. I've already used this before, and it works, even keeping qualified imports as-is. But there are some unfortunate caveats: ghci and consequently ghcid don't notice when the#include
d file changes. I've tried overcoming it with a bit of TH help:import qualified Language.Haskell.TH.Syntax as TH #include "./relative/../path/to/File.cpp.hs" $(TH.addDependentFile "/absolute/path/to/File.cpp.hs" >> pure [])
To no avail. It turns out this is a missing feature from GHCi: https://ghc.haskell.org/trac/ghc/ticket/4900#comment:81
GHCid is quite central to my workflow so this is unfortunate.
Did I miss any other approaches that some of you may be using? Maybe some that have lesser downsides or different trade-offs?