concept module in category haskell

appears as: modules, module, A module, modules, module, The module
Haskell in Depth

This is an excerpt from Manning's book Haskell in Depth.

In this chapter, we’ll explore the process of developing such a program. I’ll start by describing inputs and outputs, then move on to design issues with data types, functions and modules, followed by a discussion of useful Haskell packages and implementation details. We’ll also see how type classes can make our programs much more flexible and resilient to changes.

The code in Haskell (datatypes, function definitions, and so on) is organized into modules. There is one special module, Prelude, that is imported into every module by default. It exports the most important definitions. 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, which contains the definitions from the standard library (as defined by the Haskell 2010 Report, www.haskell.org/onlinereport/haskell2010/) together with GHC-specific additions. Many professional applications require working on many packages at the sime time. So packages are organized into projects to allow application development.

We can’t write any useful program in Haskell without importing some modules in addition to Prelude. If we stick with the base package only, we can do something basic, 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 community central package archive. Packages deliver modules ready to be imported into programs. In this chapter, we discuss many important issues concerning Haskell modules and a packaging system that every Haskell developer should be aware of.

A module declaration without an export list exports everything that is defined inside this module:

module ModuleName where

This is not a good choice except for very small modules. Remember also that instances of type classes are always exported, while imported names are never exported by default (unless we do that explicitly with the module keyword in the export list).

Figure 4.1. Correspondence between directory content and modules
modules hierarchy
Get Programming with Haskell

This is an excerpt from Manning's book Get Programming with Haskell.

$ ghci hello.hs [1 of 1] Compiling Main Ok, modules loaded: Main. *>
  • Create namespaces for your functions by using modules
  • You’ll put your palindrome code in a separate module. The module’s name will be Palindrome, so your code should be in a file named Palindrome.hs. Your Palindrome module will have a function, also named isPalindrome, which will be the function used by the Main module. You want to write a more robust version of isPalindrome so your module will also contain a series of helper functions: stripWhiteSpace, stripPunctuation, toLowerCase, and preprocess, which performs all of these. Here’s your full Palindrome.hs file.