Haskell - Wikibooks, collection of open-content textbooks

Haskell is a functional programming language. If you've programmed before and would like to see a little bit of how Haskell works and is different from other programming languages, see the overview. Haskell is unique in two ways. So, why do Haskellers like their language? In this book we aim to introduce you both to the Haskell language, from the very basics to the most advanced features, and to computer programming in general. Overview[edit] The book is divided into three sections: the Beginner's Track, the Advanced Track, and Haskell in Practice, which is designed to cover the more day-to-day issues, and is readable with knowledge of the Beginner's Track. Beginner's Track[edit] This section will introduce you to the very basics of the language and some of the more frequently used libraries. Most chapters contain exercises where you can test yourself on what you learned in that chapter. Advanced Track[edit] Haskell in Practice[edit] Appendices[edit] Syntactic sugar Answers to exercises To do
Applications and libraries
The number of Haskell packages is growing rapidly. The section 'Haskell library collections' gives an ordering of all these packages by relative importance. In the section 'Haskell applications and libraries' an ordering by category is given. Finally some guidelines for developers of new packages are presented. 1 Haskell library collections 1.1 Haskell Prelude The most important Haskell library is called the Prelude. 1.2 The Haskell 2010 libraries The Haskell 2010 Language and library specification defines a set of libraries with basic functionality which all Haskell implementations should support, including the Prelude. Haskell modules that almost everybody uses are in this group, for example: Control.Monad, Data.List and System.IO. 1.3 The GHC standard libraries GHC comes with an expanded version of the Haskell 2010 libraries. Examples of libraries, or packages, that belong to this group are: bytestring, containers and Win32. 1.4 Haskell Platform libraries 1.5 The Hackage database
introduction
Import
The statement is used to import functions and other definitions from another module. The shortest form of the import statement is that imports the named module (in this case ). However, there are more options: Modules can be imported qualified (forcing an obligatory namespace qualifier to imported identifiers). Getting all of this straight in your head is quite tricky, so here is a table (lifted directly from the language reference manual) that roughly summarises the various possibilities: Supposing that the module exports three functions named , and ... Note that multiple import statements for the same module are also allowed, so it is possible to mix and match styles if its so desired (for example, importing operators directly and functions qualified) 1 Hiding Prelude By default, every module implicitly imports . module Mod where import Prelude hiding (zip) zip = {- ... -} Without the statement, you could receive a compile-time error about an 'ambiguous use of '. ' is very messy to read.
Prelude
Parsing of Strings, producing values. Minimal complete definition: readsPrec (or, for GHC only, readPrec) Derived instances of Read make the following assumptions, which derived instances of Text.Show.Show obey: If the constructor is defined to be an infix operator, then the derived Read instance will parse only infix applications of the constructor (not the prefix form). Associativity is not used to reduce the occurrence of parentheses, although precedence may be. For example, given the declarations infixr 5 :^: data Tree a = Leaf a | Tree a :^: Tree a the derived instance of Read in Haskell 98 is equivalent to instance (Read a) => Read (Tree a) where readsPrec d r = readParen (d > app_prec) (\r -> [(Leaf m,t) | ("Leaf",s) <- lex r, (m,t) <- readsPrec (app_prec+1) s]) r ++ readParen (d > up_prec) (\r -> [(u:^:v,w) | (u,s) <- readsPrec (up_prec+1) r, (":^:",t) <- lex s, (v,w) <- readsPrec (up_prec+1) t]) r where app_prec = 10 up_prec = 5 Note that right-associativity of :^: is unused.
Related:
Related: