I am writing a (actually my first) largish program in Haskell and am trying to break up my program into modules, so that it might be easier to maintain. In Haskell, the module names seem to be dependent upon the directory structure. This is perfectly fine till I have to embed another layer of directory structure for the program. Ill give a very simple example below:
Let us say that we are starting out with a Haskell program with the following directory structure.
- Names in [square brackets] represent directories,
- names in {curly braces} represent modules,
- names in (normal brackets) represent file names associated within the modules
[src]
- (Main.hs) {Main}
- (PRBS.hs) {PRBS}
- [Hardware]
- (DataDef.hs) {Hardware.DataDef}
- (ShiftRegister.hs) {Hardware.ShiftRegister}
This is all fine. I can import everything I want wherever I want it. However, now say I want to create another level of abstraction, like so:
[src]
- (Main.hs) {Main}
- [Firmware]
- (PRBS.hs) {Firmware.PRBS}
- [Hardware]
- (DataDef.hs) {Firmware.Hardware.DataDef}
- (ShiftRegister.hs) {Firmware.Hardware.ShiftRegister}
Notice now that the names of all modules in Hardware have changed. I now have to change the module names within each file, and in all the other files where the files are imported. The three files I have shown in just an example. If the directory structure ends up having hundreds of files with tens of embedded directories, then it might become impossible to maintain code. Furthermore, if at any point, I want to copy a directory (and its subdirectories at a particular point in the current directory system), I need to figure out all the previous directories that come before it, and manually change the module names within each file.
Since Haskell is used in several large projects, I am very certain that I am missing something here. Any help in getting me out of this quagmire will be greatly appreciated!
Firmware
in GHC's import search path? (Usinghs-source-dirs
from cabal or-isrc/Firmware
for GHC) – bennofs