The Haskell Phrasebook

The Haskell Phrasebook is a free quick-start Haskell guide comprised of a sequence of small annotated programs. It provides a cursory overview of selected Haskell features, jumping-off points for further reading, and recommendations to help get you writing programs as soon as possible.

Source code

To follow along and run the code examples, get the source files from github.com/typeclasses/haskell-phrasebook.

We welcome requests and contributions, and we’re grateful to all who have submitted example code. If you have ideas for the Phrasebook, please see the contributor guide.

The code may be modified and redistributed for any non-commercial purpose with attribution.

Libraries

Here is the complete list of libraries utilized by the example programs:

  • base is the standard library, required by every Haskell program.

  • We use Seq whenever we will need to retrieve a value from a particular position in a list, and Map when we need to lookup values by an associated key. These come from the containers package.

  • hashable provides the Hashable class for types that can be used as keys in hash maps.

  • We use stm (“software transactional memory”) for all mutable references and inter-thread communication.

  • For concurrency we use either the primitives provided by base or the somewhat higher-level tools in the async library.

  • We use time for holding time in the palm of our hands.

  • We use mwc-random to generate pseudo-random numbers (MWC stands for “multiply-with-carry”).

  • cryptonite serves all of our cryptography needs.

  • We represent byte arrays using the ByteString type from the bytestring library.

  • We use some utilities from the memory library for working with byte arrays.

  • We use the utf8-string library for conversions between ByteString and String using the UTF-8 character encoding.

  • The generic-deriving library gives us some extensions to GHC’s code-generation features, such as the ability to get an automatic list of all values of a type.

  • We use the safe-exceptions library for handling I/O exceptions.

  • The process package lets our programs start other programs.

  • When we write a program that runs indefinitely, we use the signal library to listen for a termination signal.

  • The directory package lets us enumerate the contents of a directory, move files, and remove files.