20

What's the difference between module, package and library in Haskell?

From http://www.haskell.org/ghc/docs/latest/html/libraries/base/Prelude.html
Prelude: a standard module imported by default into all Haskell modules.

From http://www.haskell.org/haskellwiki/Base_package
Base package: The base package contains the Prelude and its support libraries, and a large collection of useful libraries ranging from data structures to parsing combinators and debugging utilities.

Thanks.

See also: What's the difference between a Python module and a Python package?

3
  • 2
    A package is a collection of modules, which are explained in the language report, together with data such as versions and descriptions. One often calls a package with modules that are primarily intended for use in other projects a library.
    – gspr
    Jun 8, 2013 at 9:34
  • @gspr if library is just another name for package, what does it mean when ezyang says Cabal only supports a single public library per package? source Dec 24, 2016 at 19:25
  • what about haskell program ?
    – Adam
    Aug 1, 2017 at 18:22

1 Answer 1

25

A module is a set of functions, types, classes, ... put together in a common namespace.

A library is a set of modules which makes sense to be together and that can be used in a program or another library.

A package is a unit of distribution that can contain a library or an executable or both. It's a way to share your code with the community.

Note that a library doesn't have to be in isolation in a package. That is, it's perfectly acceptable to have a library in your project that is used inside this project. The code is therefore seperated from the rest for clarity and maintainability. This is also a good way to isolate some general-purpose from your business logic code and this lib could eventually be extracted and shared between projects or with the community if needed.

2
  • 2
    Can a package also contain multiple libraries? Can a package contain different modules both inside and outside libraries? Where do signatures and interface fit in, introduced by Backpack? Dec 24, 2016 at 19:37
  • 1
    "packages are the things on Hackage" A Latter : stackoverflow.com/questions/5480982/…
    – Adam
    Aug 8, 2017 at 16:30

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.