Parallel and Concurrent Programming in Haskell
introduces the main programming models available for concurrent and
parallel
programming in Haskell. This tutorial takes a deliberately practical
approach: most of the examples are real Haskell programs that you can
compile, run, measure, modify and experiment with.
Chapters cover:
Parallel programming with the Eval monad
Evaluation Strategies
Dataow parallelism with the Par monad
Basic Concurrent Haksell
Asynchronous exceptions
Software Transactional Memory
Concurrency and the Foreign Function Interface
High-speed concurrent servers
In order to follow this tutorial you should have a basic
knowledge of Haskell, including programming with monads.
A Gentle Introduction to Haskell Version 98 is
intended to serve as a supplement to the Haskell Report. The authors
aim to offer a general introduction to Haskell for anyone who has some
experience of another language.
Chapters cover:
Introduction
Values, Types, and Other Goodies - all
computations are done via the evaluation of expressions (syntactic
terms) to yield values
Functions - looks at several aspects of functions in
Haskell
Case Expressions and Pattern Matching - looks at the
pattern-matching process in greater detail
Type Classes and Overloading
Types, Again - examines some of the more
advanced aspects of type declarations
Input/Output - the I/O system in Haskell is purely
functional, yet has all of the expressive power found in conventional
programming languages
Standard Haskell Classes - introduces the
predefined standard type classes in Haskell
Monads - addresses not only the language features
that involve monads but also tries to reveal the bigger picture: why
monads are such an important tool and how they are used
Numbers - Haskell provides a rich collection of
numeric types, based on those of Scheme, which in turn are based on
Common Lisp
Modules - serves the dual purpose of
controlling name-spaces and creating abstract data types
Typing Pitfalls - gives an intuitive
description of a few common problems that novices run into using
Haskell's type system
Arrays - index types, array creation, accumulation,
incremental updates, and an example: matrix multiplication
The aim of this book is to introduce the reader to both
the Haskell language and to computer programming in general. The book
covers all stages, from the very basics to the most advanced features
of Haskell. It is divided into 3 sections: The Beginner's
Track, the Advanced Track, and Practical Haskell.
Beginner's Track
The first section introduces the reader to the very
basics of the language and some of the more frequently used libraries.
Haskell Basics:
Getting set up - explore how to install the
programs you will need to start coding in Haskell
Variables and functions - keep track of
intermediate results. A function takes an argument value (or
parameter) and gives a result value, like a variable, that takes its
place
Truth values - equality and other comparisons,
boolean values, introduction to types, infix operators, boolean
operations, and guards
Type basics - Types in programming are a way of
grouping similar values into categories. In Haskell, the type system is
a powerful way of ensuring there are fewer mistakes in your code
Lists and tuples - the two most fundamental ways of
manipulating several values together, by grouping them into a single
value
Type basics II - the num class, numeric types, and
classes beyond numbers
Building vocabulary - discusses the importance of
acquiring a vocabulary of functions and how this book, along with other
resources, can help you with that
Next steps - introduces pattern matching, if
expressions and let bindings
Simple input and output - actions, and actions
under the microscope
Elementary Haskell:
Recursion - a form of repetition, looks at numeric
recursion, other recursive functions, and list-based recursion
More about lists - rebuilding lists, generalizing,
the map function, tips and tricks
List processing - folds, scans, filter, and list
comprehensions (a powerful, concise and expressive syntactic construct)
Type declarations - data and constructor functions,
deconstructing types, and type for making type synonyms
Pattern matching - takes a deeper look at pattern
matching
Control structures - introduces a new control
structure, case expressions
More on functions - let and where revisited,
anonymous functions - lambdas, operators and sections
Higher order functions and Currying - Higher-order
functions are functions that take other functions as arguments.
Currying is a technique that lets you partially apply a multi-parameter
function
Using GHCi effectively - describes several ways
that GHCi can make you work faster
Intermediate Haskell:
Modules - Haskell modules are a useful way to group
a set of related functionalities into a single
package and manage a set of different functions that have the same name
Indentation - helps the reader to get a grip with
the indentation rules
More on datatypes - enumerations, named fields
(record syntax), and parameterized types
Other data structures - trees, and other datatypes
Classes and types - see how to define and implement
type classes, and how to use them to our advantage
The Functor class - introduces the very important
Functor class, use it as a simple example of how type classes can be
useful tools for solving problems in a more general way
Monads:
Understanding monads - introduces the basic notions
with the example of the Maybe monad, the simplest monad for handling
exceptions
The Maybe monads - represents computations which
might "go wrong", in the sense of not returning a value
The List monad - taken as monads, lists are used to
model nondeterministic computations which may return an arbitrary
number of result
do Notation
The IO monad - solves some problems for Haskell
having simple input/output
The State monad - introduced to allow states of any
complexity to be represented
Additive monads (MonadPlus) - defines two methods.
mzero is the monadic value standing for zero results; while
mplus is a binary function which combines two computations
Monadic parser combinators - Monads provide a clean
means of embedding a domain specific parsing language directly
into Haskell without the need for external tools or code generators
Monad transformers - special types that allow us to
roll two monads into a single one that shares the behaviour of both
Practical monads - parsing monads and generic monads
Advanced
Track
This section introduces wider functional programming
concepts such as
different data structures and type theory. It also covers more
practical topics like concurrency.
Advanced Haskell:
Arrows - a generalization of monads: every
monad gives rise to an arrow, but not all arrows give rise to monads
Understanding arrows - presents arrows from the
perspective of stream processors, using the
factory metaphor from the monads module as a support
Continuation passing style (CPS) - a format for
expressions such that no function ever returns,
instead they pass control onto a continuation
Zippers - Theseus and the Zipper, differentiation
of data types
Applicative Functors - functors with some extra
properties, the most important one is
that it allows you to apply functions inside the functor (hence the
name) to other values
Monoids - a more detailed look into monoids and the
monoid type class
Mutable objects - discusses advanced programming
techniques for using imperative constructs, such as references
and mutable arrays, without compromising (too much) purity
Concurrency - in Haskell is mostly done with
Haskell threads
Fun with Types:
Polymorphism basics - parametric polymorphism, the
forall keyword, example: heterogeneous lists, explaining the term
existential, and example: runST
Advanced type classes - multi-parameter type
classes, functional dependencies, and examples
Phantom types - a way to embed a language with a
stronger type system than Haskell's
Generalised algebraic data-types (GADT) - allows
you to explicitly write down the types of the constructors. This
chapter explains why this is useful and how to declare them
Type constructors & Kinds
Wider Theory:
Denotational semantics - explains how to formalize
the meaning of Haskell programs, the
denotational semantics
Category theory - gives an overview of category
theory, in so far as it applies to Haskel
The Curry-Howard isomorphism - a striking
relationship connecting two seemingly
unrelated areas of mathematics — type theory and structural logic
fix and recursion
Haskell Performance:
Introduction - execution model, algorithms
& data structures, and parallelism
Step by Step Examples
Graph reduction - evaluating expressions by lazy
evaluation, controlling space, reasoning about time, and implementation
of graph reduction
Laziness
Strictness - difference between strict and lazy
evaluation, why laziness can be problematic
Algorithm complexity
Data structures
Parallelism
Haskell in Practice:
This section covers the more day-to-day issues of
working with Haskell,
issues such as making use of the standard library, building graphical
interfaces or working with databases.
Topics cover:
Libraries Reference:
The Hierarchical Libraries
Lists - the List datatype is the fundamental data
structure in Haskell
Arrays - the libraries support 9 types of array
constructors: Array, UArray, IOArray, IOUArray, STArray, STUArray,
DiffArray,
DiffUArray and StorableArray
Maybe - the Maybe data type
Maps - the module Data.Map provides the Map
datatype, which allows you to store values attached to specific keys
IO - looks at the IO library
Random Numbers - includes the standard random
number generator, and using QuickCheck to generate random data
General Practices:
Building a standalone application
Debugging - shows how to use the Debug.Trace module
Testing - testing with QuickCheck
Packing your software (Cabal) - a guide to the best
practice for creating a new Haskell project or program
Using the Foreign Function Interface (FFI) - using
libraries written in other languages
Generic Programming: Scrap your boilerplate - a way
to allow your data structures to
be traversed by so-called "generic" function
Specialised Tasks:
Graphical user interfaces - focuses on the
wxHaskell toolkit
Databases - general workflow, running queries
Web programming
Working with XML - examines libraries for parsing
and generating XML
Using Regular Expressions - a pointer to some good
tutorials
Parsing Mathematical Expression - discusses how to
turn strings of text such as "3*sin x + y" into an abstract
syntactic representation like Plus (Times (Number 3) (Apply "sin"
(Variable "x"))) (Variable "y")
The book is licensed under the Creative Commons
Attribution-ShareAlike 3.0 Unported license.