The anatomy of a Haskell project
A typical Haskell project consists of one or several of the following sections:
Library (modules); A no-brainer for library authors. But most applications are also structured so that most code resides in distinct modules.
One or more executables.
Tests and benchmarks.
Other source files and assets.
All of these are supported by Cabal. Starting with a new project from scratch, we can use cabal init
to create a .cabal
file with basic information such as the package name and maintainer details already filled in. Moreover, if you already have a bunch of Haskell source files in your working directory, then Cabal will add those to the .cabal
file and even guess package dependencies for you.
The structure often found in projects that have both a library and an executable is to place library code and the executable's source files under different subdirectories. If we have a single library module, dubbed Lib
, and a main
, the structure would be:
some-package/ src/Lib.hs...