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.

4.1  Haskell programs as collections of modules

 
 
 

4.1.1  Module structure, imports, and exports

 
 
 
 

4.1.2  Using custom preludes for encouraging best practices

 
 

4.2  Understanding Haskell packaging

 
 
 

4.2.1  Packaging at the compiler level

 
 

4.2.2  Cabal packages and Hackage

 

4.2.3  Versioning packages

 
 

4.3  Tools for Haskell project management

 
 

4.3.1  Traditional package management with cabal-install

 

4.3.2  Nix-style local package management with cabal-install

 

4.3.3  Using stack and Stackage for Haskell development

 
 
 

4.3.4  Continuous integration for Haskell projects

 
 

4.4  Summary

 
 
 
 
sitemap

Unable to load book!

The book could not be loaded.

(try again in a couple of minutes)

manning.com homepage
test yourself with a liveTest