How to use libraries
Library API documentation is typically autogenerated from code comments, to create online interactive docs.
As an example,
gloss is a package for 2D animation and games. Here are its API docs, where you can find the following package list:
For well-maintained packages, you should expect to find some explanation of the package's goals and uses either on this front page or in the top-level module (here
Many published packages are experimental code, not intended for serious use. To get a sense of which packages to use, see this guide.
Hackage and Stackage¶
How to read Haskell documentation¶
Haskell's expressive types are usually very helpful in understanding how to use a library. For example, the following function appears near the top of the docs in the top level module:
From the type signature, we see that we get a runnable process (i.e. a value of type
IO ()) if we supply a few arguments, like
Color and a function
Float -> Picture.
We can then understand what
Picture is by following the link, to see its definition:
Haskell's Prelude library is automatically imported into every module, and includes many familiar functions and types, like
Prelude is sometimes replaced by a different base library in large projects, since it includes legacy features and outdated design decisions. For example, the function
head is unsafe in the sense that it throws a hard error when you take the head of an empty list:
A good modern alternative can be found here.
Created: January 8, 2023