In programming, libraries are collections of precompiled routines that can be used in other programs. Usually, a library stores frequently used routines (for example, reading or printing an input), or it is specialized for a particular subject (for example, the libraries used in the statistics field). In this chapter, you will learn about the main libraries in Haskell and when you can use them to create powerful programs.
Prelude
The main library in Haskell is Prelude, which is imported by default when you install GHC.
Prelude contains standard types and classes, operations on lists, conversion techniques from a value to a String and vice versa, basic input and output operations and functions, basic exception handling, and functions for types.
The previous example is simple. If the second argument of the division function is 0, then you print an error message; otherwise, you print the result of division between the two arguments.
Haskell 2010 Libraries
The language and library specification of Haskell 2010 contains a collection of libraries with basic functionalities included in all Haskell implementations. The libraries are maintained by the Haskell process, and you can find the complete list of Haskell 2010 libraries in [1].
Two important packages are base (which includes modules like Control.Monad, Data.List, and System.IO) and vector (which includes modules such as Data.Vector).
GHC Bootstrap Libraries
GHC Bootstrap libraries are an extension of the Haskell 2010 libraries, used to build GHC itself. Examples of such libraries are haskeline and integer-gmp., For this chapter, you don’t need packages from this collection.
Core Libraries and Haskell Platform Libraries
Core libraries are part of the management process, defining the basic APIs that can be used in any Haskell implementation, the packages for backward compatibility, or the packages that are needed to link things in the Haskell platform together. Examples of such libraries and packages are the Monad transformer library, random, and parallel.
In addition to the core libraries, the Haskell platform libraries contain more complex packages such as attoparsec, network, and QuickCheck.
The Hackage Database
The Hackage database contains a huge list of libraries, specializing in a large range of subjects, such as blockchain, chemistry, files, hydrology, scientific simulation, and so on. You can find the complete list of packages grouped by subjects in [2].
Summary
In this chapter, you learned about classified packages and libraries in Haskell. Note that because Haskell is an open source platform, anyone can create libraries. A short tutorial of the processes involved in creating and submitting a library can be found in [3] or [4].
References
- 1.
Part II, the Haskell 2010 libraries, https://www.haskell.org/onlinereport/haskell2010/haskellpa2.html
- 2.
Packages by category, http://hackage.haskell.org/packages/
- 3.
How to write a Haskell program, https://wiki.haskell.org/How_to_write_a_Haskell_program
- 4.
Creating a package, https://downloads.haskell.org/~ghc/7.0.4/docs/html/Cabal/authors.html
- 5.
Applications and libraries, https://wiki.haskell.org/Applications_and_libraries