Cabal Projects
The executable
field specifies the part of the package which can be executed with cabal run <executable>
.
main-is
- The executable file containing aMain
module and the functionmain
.build-depends
- Other library packages from which modules are imported. This can contain modules from the current package itself if they are found in theexposed-modules
field of thelibrary
, by specifying the name of our package.hs-source-dirs
- The local directories from which the executable can be found (leave empty if it isn’t inside a directory) and any other local modules it imports (if they aren’t found in thebuild-depends
field).other-modules
- Other modules included in the executable should be listed in the other-modules field.
For an executable, cabal init
does not try to guess which file contains your program’s Main
module. You will need to fill in the executable:main-is
field with the file name of your program’s Main
module (including .hs
or .lhs
extension).
The library
field specifies the exposed modules of our package that make up the public interface of the library. The name of a library always matches the name of the package, so it is not specified in the library section.
exposed-modules
- The modules we choose to export from our package and make available to be used as part of its public interface.hs-source-dirs
- The directories from which the exposed modules can be found.build-depends
- Other library packages from which modules. Most of the build information fields are the same between libraries and executables.other-modules
- For modules that do not form part of our package’s public interface, you can move those modules to the other-modules field. Either way, all modules in the library need to be listed.
For a library, cabal init
looks in the project directory for files that look like Haskell modules and adds all the modules to the library:exposed-modules
field.
For module names and organisation of directories, the module prefixes indicate the directory the module is found in. For example:
library
...
hs-source-dirs: src
exposed-modules: PmmhHmm
Monad.Coroutine
Monad.Coroutine.Nested
Monad.Coroutine.SuspensionFunctors
...
This indicates that our project must look like:
src/
PmmhHmm.hs -- module PmmhHmm
Monad/
Coroutine.hs -- module Monad.Coroutine
Coroutine/
Nested.hs -- module Monad.Coroutine.Nested
SuspensionFunctors.hs -- module Monad.Coroutine.SuspensionFunctors