Probabilistic Effects. λθ

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 a Main module and the function main.
  • build-depends - Other library packages from which modules are imported. This can contain modules from the current package itself if they are found in the exposed-modules field of the library, 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 the build-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
Last updated on 13 Nov 2020
Published on 13 Nov 2020