Real World Haskell

  • Introduction: Why Haskell?
    • Have we got a deal for you!
    • What to expect from this book
    • What to expect from Haskell
    • A brief sketch of Haskell’s history
    • Helpful resources
    • Acknowledgments
  • Chapter 1: Getting Started
    • Your Haskell environment
    • Getting started with ghci, the interpreter
    • Basic interaction: using ghci as a calculator
    • Command line editing in ghci
    • Lists
    • Strings and characters
    • First steps with types
    • A simple program
    • Exercises
  • Chapter 2: Types and Functions
    • Why care about types?
    • Haskell’s type system
    • What to expect from the type system
    • Some common basic types
    • Function application
    • Useful composite data types: lists and tuples
    • Functions over lists and tuples
    • Function types and purity
    • Haskell source files, and writing simple functions
    • Understanding evaluation by example
    • Polymorphism in Haskell
    • The type of a function of more than one argument
    • Exercises
    • Why the fuss over purity?
    • Conclusion
  • Chapter 3: Defining Types, Streamlining Functions
    • Defining a new data type
    • Type synonyms
    • Algebraic data types
    • Pattern matching
    • Record syntax
    • Parameterised types
    • Recursive types
    • Reporting errors
    • Introducing local variables
    • The offside rule and white space in an expression
    • The case expression
    • Common beginner mistakes with patterns
    • Conditional evaluation with guards
    • Exercises
  • Chapter 4: Functional Programming
    • Thinking in Haskell
    • A simple command line framework
    • Warming up: portably splitting lines of text
    • Infix functions
    • Working with lists
    • How to think about loops
    • Anonymous (lambda) functions
    • Partial function application and currying
    • As-patterns
    • Code reuse through composition
    • Tips for writing readable code
    • Space leaks and strict evaluation
  • Chapter 5: Writing a library: working with JSON data
    • A whirlwind tour of JSON
    • Representing JSON data in Haskell
    • The anatomy of a Haskell module
    • Compiling Haskell source
    • Generating a Haskell program, and importing modules
    • Printing JSON data
    • Type inference is a double-edged sword
    • A more general look at rendering
    • Developing Haskell code without going nuts
    • Pretty printing a string
    • Arrays and objects, and the module header
    • Writing a module header
    • Fleshing out the pretty printing library
    • Creating a package
    • Practical pointers and further reading
  • Chapter 6: Using Type Classes
    • The need for type classes
    • What are type classes?
    • Declaring type class instances
    • Important Built-In Type Classes
    • Automatic Derivation
    • Type classes at work: making JSON easier to use
    • Flexible instances
    • Living in an open world
    • How to give a type a new identity
    • JSON type classes without overlapping instances
    • The dreaded monomorphism restriction
    • Conclusion
  • Chapter 7: I/O
    • Classic I/O in Haskell
    • Working With Files and Handles
    • Extended Example: Functional I/O and Temporary Files
    • Lazy I/O
    • The IO Monad
    • Is Haskell Really Imperative?
    • Side Effects with Lazy I/O
    • Buffering
    • Reading Command-Line Arguments
    • Environment Variables
  • Chapter 8: Efficient File Processing, Regular Expressions, and File Name Matching
    • Efficient file processing
    • File name matching
    • Regular expressions in Haskell
    • More about regular expressions
    • Translating a glob pattern into a regular expression
    • An important aside: writing lazy functions
    • Making use of our pattern matcher
    • Handling errors through API design
    • Putting our code to work
    • Exercises
  • Chapter 9: I/O case study: a library for searching the filesystem
    • The find command
    • Starting simple: recursively listing a directory
    • A naive finding function
    • Predicates: from poverty to riches, while remaining pure
    • Sizing a file safely
    • A domain specific language for predicates
    • Controlling traversal
    • Density, readability, and the learning process
    • Another way of looking at traversal
    • Useful coding guidelines
    • Exercises
  • Chapter 10: Code case study: parsing a binary data format
    • Greyscale files
    • Parsing a raw PGM file
    • Getting rid of boilerplate code
    • Implicit state
    • Introducing functors
    • Writing a functor instance for Parse
    • Using functors for parsing
    • Rewriting our PGM parser
    • Future directions
    • Exercises
  • Chapter 11: Testing and Quality Assurance
    • QuickCheck: type-based testing
    • Testing case study: specifying a pretty printer
    • Measuring test coverage with HPC
  • Chapter 12: Barcode Recognition
    • A little bit about barcodes
    • Introducing arrays
    • Encoding an EAN-13 barcode
    • Constraints on our decoder
    • Divide and conquer
    • Turning a colour image into something tractable
    • What have we done to our image?
    • Finding matching digits
    • Life without arrays or hash tables
    • Turning digit soup into an answer
    • Working with row data
    • Pulling it all together
    • A few comments on development style
  • Chapter 13. Data Structures
    • Association Lists
    • Maps
    • Functions Are Data, Too
    • Extended Example: /etc/passwd
    • Extended example: Numeric Types
    • Taking advantage of functions as data
    • General purpose sequences
  • Chapter 14. Monads
    • Introduction
    • Revisiting earlier code examples
    • Looking for shared patterns
    • The Monad type class
    • And now, a jargon moment
    • Using a new monad: show your work!
    • Mixing pure and monadic code
    • Putting a few misconceptions to rest
    • Building the Logger monad
    • The Maybe monad
    • The list monad
    • Desugaring of do blocks
    • The state monad
    • Another way of looking at monads
    • The monad laws, and good coding style
  • Chapter 15. Programming with monads
    • Golfing practice: association lists
    • Generalised lifting
    • Looking for alternatives
    • Adventures in hiding the plumbing
    • Separating interface from implementation
    • The reader monad
    • A return to automated deriving
    • Hiding the IO monad
  • Chapter 16. Using Parsec
    • First Steps with Parsec: Simple CSV Parsing
    • The sepBy and endBy Combinators
    • Choices and Errors
    • Extended Example: Full CSV Parser
    • Parsec and Alternative
    • Parsing an URL-encoded query string
    • Supplanting regular expressions for casual parsing
    • Parsing without variables
    • Applicative functors for parsing
    • Applicative parsing by example
    • Parsing JSON data
    • Parsing a HTTP request
  • Chapter 17. Interfacing with C: the FFI
    • Foreign language bindings: the basics
    • Regular expressions for Haskell: a binding for PCRE
    • Passing string data between Haskell and C
    • Matching on strings
  • Chapter 18. Monad transformers
    • Motivation: boilerplate avoidance
    • A simple monad transformer example
    • Common patterns in monads and monad transformers
    • Stacking multiple monad transformers
    • Moving down the stack
    • Understanding monad transformers by building one
    • Transformer stacking order is important
    • Putting monads and monad transformers into perspective
  • Chapter 19. Error handling
    • Error Handling with Data Types
    • Exceptions
    • Exercises
    • Error handling in monads
  • Chapter 20. Systems Programming in Haskell
    • Running External Programs
    • Directory and File Information
    • Program Termination
    • Dates and Times
    • Extended Example: Piping
  • Chapter 21. Using Databases
    • Overview of HDBC
    • Installing HDBC and Drivers
    • Connecting to Databases
    • Transactions
    • Simple Queries
    • SqlValues
    • Query Parameters
    • Prepared Statements
    • Reading Results
    • Database Metadata
    • Error Handling
  • Chapter 22. Extended Example: Web Client Programming
    • Basic Types
    • The Database
    • The Parser
    • Downloading
    • Main Program
  • Chapter 23. GUI Programming with gtk2hs
    • Installing gtk2hs
    • Overview of the GTK+ Stack
    • User Interface Design with Glade
    • Event-Driven Programming
    • Initializing the GUI
    • The Add Podcast Window
    • Long-Running Tasks
    • Using Cabal
    • Exercises
  • Chapter 24. Concurrent and multicore programming
    • Defining concurrency and parallelism
    • Concurrent programming with threads
    • Simple communication between threads
    • The main thread and waiting for other threads
    • Communicating over channels
    • Useful things to know about
    • Shared-state concurrency is still hard
    • Exercises
    • Using multiple cores with GHC
    • Parallel programming in Haskell
    • Parallel strategies and MapReduce
  • Chapter 25. Profiling and optimization
    • Profiling Haskell programs
    • Controlling evaluation
    • Understanding Core
    • Advanced techniques: fusion
  • Chapter 26. Advanced library design: building a Bloom filter
    • Introducing the Bloom filter
    • Use cases and package layout
    • Basic design
    • The ST monad
    • Designing an API for qualified import
    • Creating a mutable Bloom filter
    • The immutable API
    • Creating a friendly interface
    • Creating a Cabal package
    • Testing with QuickCheck
    • Performance analysis and tuning
    • Exercises
  • Chapter 27. Sockets and Syslog
    • Basic Networking
    • Communicating with UDP
    • Communicating with TCP
  • Chapter 28. Software transactional memory
    • The basics
    • Some simple examples
    • STM and safety
    • Retrying a transaction
    • Choosing between alternatives
    • I/O and STM
    • Communication between threads
    • A concurrent web link checker
    • Practical aspects of STM
  • Appendix. Characters, strings, and escaping rules
    • Writing character and string literals
    • International language support
    • Escaping text
  • Bibliography