This separation of modules between folders can be anything you want. The naive idea is that you paste almost all the logic into the Lib folder, and Main.hs simply imports the required parts of Lib , reads the command line arguments and starts the material. You can rename the app to executables and change the corresponding lines in the .cabal file. In fact, you can create an arbitrary file hierarchy.
In our project, we use a different, but very popular approach. And our file hierarchy looks like this:
. |-- bench |-- src |-- exec1 |-- Main.hs |-- exec2 |-- Main.hs |-- SuperCoolLibraryName |-- LibModule1.hs |-- LibModule2.hs |-- test |-- Setup.hs
And other stack.yaml , .cabal files, etc.
Actually, if you are writing an application, you can simply create one Main.hs file and put all the logic inside main . You will not believe it, but as a Haskell teacher, I saw this code from my students :( Although I do not suggest you write code in this way.
If you are writing a library, you do not need Main.hs and main files. You can look at a simple example, for example, this library (it allows you to automatically generate command-line options from data types): optparse-generic
PS Sorry for my English, I hope I helped you with your confusion.
source share