I.The Language 7 1.What is Haskell? 9 Functional Programming Concepts 9 Values 9 Expressions 9 Functions and Parameters 9 Recursion 9 Functions as Values 9 Strictness vs. Laziness 10 A Comparison with Procedural and Object-Oriented Languages 10 A Comparison with Other Functional Languages 10 2.Using Haskell Code 11 Using a Haskell Interpreter: HUGS 11 Using a Haskell Compiler: GHC 11 Using Haskell with Web Servers 11 Using Haskell for CGI 11 Using Haskell with mod_haskell 11 3.Values and Expressions 13 Values 13 Literals 13 Names 13 Expressions and Precedence 13 Calling Functions 13 Expressions that Produce Functions 14 "Changing State" by Creating New Values 14 4.Naming your Expressions 15 Naming an Expression 15 The Basic Syntax 15 Layout 15 Using C-style Braces and Semicolons 15 Reusing a Named Expression 15 Why We Haven't Mentioned Types Yet 15 Inferring a Type 15 The Type of a Function 16 Telling Haskell the Type When It Can't Figure It Out 16 5.Defining Your Own Operators 17 Defining an Operator 17 Setting Precedence 17 Operators are Just Syntactic Sugar 17 6.HaSh, or Using Haskell for a Shell 19 Hugs: A Calculator on Steroids 19 The Prelude: All the Usual Suspects 19 Loading Other Modules 19 Handling IO with White Gloves 19 Laziness - Change Nothing Until It Must 19 Using >>=, >>, and return 20 A Little Formalism: The Class "Monad" 20 Haskell as a Shell 20 File IO 20 Shell Commands 20 7.Software Engineering 21 Using Modules 21 Exports 21 Imports 21 Using Classes 21 Defining a Class 21 Defining an Instance 21 Deriving a Class 21 II.A Brief Cookbook 23 8.Grep 25 Our Specification: Simple Grep 25 Command-line Parameters 25 File Manipulation 25 Searching and Outputting Results 25 9.A JPEG Codec and Browser 27 Our Specification: JPEG file formats and OpenGL Display 27 A Desecription of JPEG 27 Encoding (Hint - the description is the code) 27 Decoding 27 An External Library: OpenGL 27 10.Database Access 29 Our Specification: Web Logs in SQL Databases 29 Parsing the Log File 29 Parsing Web-Search-Style Queries 29 Data Mining 29 III.The Libraries 31 11.Array 33 Exports 33 From This Module 33 From Others 33 Classes 33 Types and Constructor 33 Instances 33 Functions and Operators 34 12.Char 35 Exports 35 From This Module 35 From Others 35 Classes 35 Types and Constructor 35 Instances 35 Functions and Operators 36 13.Complex 37 Exports 37 From This Module 37 From Others 37 Classes 37 Types and Constructor 37 Instances 37 Functions and Operators 38 14.IO 39 Exports 39 From This Module 39 From Others 39 Classes 39 Types and Constructor 39 Instances 39 Functions and Operators 40 15.Ix 41 Exports 41 From This Module 41 From Others 41 Classes 41 Types and Constructor 41 Instances 41 Functions and Operators 42 16.List 43 Exports 43 From This Module 43 From Others 43 Classes 43 Types and Constructor 43 Instances 43 Functions and Operators 44 17.Locale 45 Exports 45 From This Module 45 From Others 45 Classes 45 Types and Constructor 45 Instances 45 Functions and Operators 46 18.Maybe 47 Exports 47 From This Module 47 From Others 47 Classes 47 Types and Constructor 47 Instances 47 Functions and Operators 48 19.Monad 49 Exports 49 From This Module 49 From Others 49 Classes 49 Types and Constructor 49 Instances 49 Functions and Operators 50 20.Numeric 51 Exports 51 From This Module 51 From Others 51 Classes 51 Types and Constructor 51 Instances 51 Functions and Operators 52 21.Prelude 53 Exports 53 From This Module 53 From Others 53 Classes 53 Types and Constructor 53 Instances 53 Functions and Operators 54 22.Random 55 Exports 55 From This Module 55 From Others 55 Classes 55 Types and Constructor 55 Instances 55 Functions and Operators 56 23.Ratio 57 Exports 57 From This Module 57 From Others 57 Classes 57 Types and Constructor 57 Instances 57 Functions and Operators 58 24.System 59 Exports 59 From This Module 59 From Others 59 Classes 59 Types and Constructor 59 Instances 59 Functions and Operators 60