4 Structuring programs with modules and packages
This chapter covers:
- Best practices in structuring your program with modules
- Using custom preludes
- Ideas and approaches behind packaging Haskell projects
- Particular tools for package management
The code in Haskell (datatypes, function definitions, and so on) is organized into modules. Modules form packages. Packages may contain libraries intended to be used by other packages, or standalone applications, or both. There is one special package, base
, that contains the definitions from the standard library (as defined by the Haskell 2010 Report, www.haskell.org/onlinereport/haskell2010/) together with GHC-specific additions. There is one special module, Prelude
, that is imported into the modules of your program by default; it exports the most important definitions.
You can’t write any useful program in Haskell without importing some modules in addition to Prelude
. If you stick with the base
package only, you’ll be able to do something simple, but that’s it. Every Haskell programmer benefits from using libraries that have been created by other programmers and are available in the form of packages on Hackage (hackage.haskell.org/), the Haskell’s community central package archive. Packages deliver modules ready to be imported into your programs. In this chapter we’ll discuss some important issues concerning Haskell modules and the packaging system that every programmer must be aware of.