Haskell/Hierarchical libraries

Hierarchical libraries (Solutions)
Libraries Reference

The Hierarchical Libraries
Lists
Arrays
Maybe
Maps
IO
Random Numbers

Haskell has a rich and growing set of function libraries. They fall into several groups:

  • The Standard Prelude (often referred to as just "the Prelude") is defined in the Haskell 98 standard and imported automatically to every module you write. This defines standard types such as strings, lists and numbers and the basic functions on them, such as arithmetic, map and foldr
  • The Standard Libraries are also defined in the Haskell 98 standard, but you have to import them when you need them. The reference manuals for these libraries are at http://www.haskell.org/onlinereport/
  • Since 1998 the Standard Libraries have been gradually extended, and the resulting de-facto standard is known as the Base libraries. The same set is available for both HUGS and GHC.
  • Other libraries may be included with your compiler, or can be installed using the Cabal mechanism.

When Haskell 98 was standardised modules were given a flat namespace. This has proved inadequate and a hierarchical namespace has been added by allowing dots in module names. For backward compatibility the standard libraries can still be accessed by their non-hierarchical names, so the modules List and Data.List both refer to the standard list library.

For details of how to import libraries into your program, see Modules and libraries. For an explanation of the Cabal system for packaging Haskell software see Haskell/Packaging.

Haddock DocumentationEdit

Library reference documentation is generally produced using the Haddock tool. The libraries shipped with GHC are documented using this mechanism. You can view the documentation at http://www.haskell.org/ghc/docs/latest/html/libraries/index.html, and if you have installed GHC then there should also be a local copy.

Haddock produces hyperlinked documentation, so every time you see a function, type or class name you can click on it to get to the definition. The sheer wealth of libraries available can be intimidating, so this tutorial will point out the highlights.

One thing worth noting with Haddock is that types and classes are cross-referenced by instance. So for example in the Data.Maybe library the Maybe data type is listed as an instance of Ord:

Ord a => Ord (Maybe a)

This means that if you declare a type Foo is an instance of Ord then the type Maybe Foo will automatically be an instance of Ord as well. If you click on the word Ord in the document then you will be taken to the definiton of the Ord class and its (very long) list of instances. The instance for Maybe will be down there as well.

Hierarchical libraries
Solutions to exercises
Libraries Reference

The Hierarchical Libraries  >> Lists >> Arrays >> Maybe >> Maps  >> IO >> Random Numbers


Haskell

Haskell Basics >> Elementary Haskell >> Intermediate Haskell >> Monads
Advanced Haskell >> Fun with Types >> Wider Theory >> Haskell Performance


Libraries Reference >> General Practices >> Specialised Tasks

Last modified on 29 April 2012, at 03:20