The Maybe type encapsulates an optional value. A value of type
Maybe a either contains a value of type a (represented as Just a),
or it is empty (represented as Nothing). Using Maybe is a good way to
deal with errors or exceptional cases without resorting to drastic
measures such as error.

The Maybe type is also a monad. It is a simple kind of error
monad, where all errors are represented by Nothing. A richer
error monad can be built using the Data.Either.Either type.

The maybe function takes a default value, a function, and a Maybe
value. If the Maybe value is Nothing, the function returns the
default value. Otherwise, it applies the function to the value inside
the Just and returns the result.

The Either type represents values with two possibilities: a value of
type Either a b is either Left a or Right b.

The Either type is sometimes used to represent a value which is
either correct or an error; by convention, the Left constructor is
used to hold an error value and the Right constructor is used to
hold a correct value (mnemonic: "right" also means "correct").

The character type Char is an enumeration whose values represent
Unicode (or equivalently ISO/IEC 10646) characters
(see http://www.unicode.org/ for details).
This set extends the ISO 8859-1 (Latin-1) character set
(the first 256 charachers), which is itself an extension of the ASCII
character set (the first 128 characters).
A character literal in Haskell has type Char.

To convert a Char to or from the corresponding Int value defined
by Unicode, use Prelude.toEnum and Prelude.fromEnum from the
Prelude.Enum class respectively (or equivalently ord and chr).

The enumFrom... methods are used in Haskell's translation of
arithmetic sequences.

Instances of Enum may be derived for any enumeration type (types
whose constructors have no fields). The nullary constructors are
assumed to be numbered left-to-right by fromEnum from 0 through n-1.
See Chapter 10 of the Haskell Report for more details.

For any type that is an instance of class Bounded as well as Enum,
the following should hold:

The Bounded class is used to name the upper and lower limits of a
type. Ord is not a superclass of Bounded since types that are not
totally ordered may also have upper and lower bounds.

The Bounded class may be derived for any enumeration type;
minBound is the first constructor listed in the data declaration
and maxBound is the last.
Bounded may also be derived for single-constructor datatypes whose
constituent types are in Bounded.

Monads and functors

The Monad class defines the basic operations over a monad,
a concept from a branch of mathematics known as category theory.
From the perspective of a Haskell programmer, however, it is best to
think of a monad as an abstract datatype of actions.
Haskell's do expressions provide a convenient syntax for writing
monadic expressions.

Application operator. This operator is redundant, since ordinary
application (f x) means the same as (f $ x). However, $ has
low, right-associative binding precedence, so it sometimes allows
parentheses to be omitted; for example:

f $ g $ h x = f (g (h x))

It is also useful in higher-order situations, such as map ($ 0) xs,
or Data.List.zipWith ($) fs xs.

Applied to a predicate and a list, any determines if any element
of the list satisfies the predicate. For the result to be
False, the list must be finite; True, however, results from a True
value for the predicate applied to an element at a finite index of a finite or infinite list.

Applied to a predicate and a list, all determines if all elements
of the list satisfy the predicate. For the result to be
True, the list must be finite; False, however, results from a False
value for the predicate applied to an element at a finite index of a finite or infinite list.

maximum returns the maximum value from a list,
which must be non-empty, finite, and of an ordered type.
It is a special case of maximumBy, which allows the
programmer to supply their own comparison function.

minimum returns the minimum value from a list,
which must be non-empty, finite, and of an ordered type.
It is a special case of minimumBy, which allows the
programmer to supply their own comparison function.

break, applied to a predicate p and a list xs, returns a tuple where
first element is longest prefix (possibly empty) of xs of elements that
do not satisfyp and second element is the remainder of the list:

Searching lists

elem is the list membership predicate, usually written in infix form,
e.g., x `elem` xs. For the result to be
False, the list must be finite; True, however, results from an element equal to x found at a finite index of a finite or infinite list.

zipWith generalises zip by zipping with the function given
as the first argument, instead of a tupling function.
For example, zipWith (+) is applied to two lists to produce the
list of corresponding sums.

Derived instances of Show have the following properties, which
are compatible with derived instances of Text.Read.Read:

The result of show is a syntactically correct Haskell
expression containing only constants, given the fixity
declarations in force at the point where the type is declared.
It contains only the constructor names defined in the data type,
parentheses, and spaces. When labelled constructor fields are
used, braces, commas, field names, and equal signs are also used.

If the constructor is defined to be an infix operator, then
showsPrec will produce infix applications of the constructor.

the representation will be enclosed in parentheses if the
precedence of the top-level constructor in x is less than d
(associativity is ignored). Thus, if d is 0 then the result
is never surrounded in parentheses; if d is 11 it is always
surrounded in parentheses, unless it is an atomic expression.

If the constructor is defined using record syntax, then show
will produce the record-syntax form, with the fields given in the
same order as the original declaration.

The method showList is provided to allow the programmer to
give a specialised way of showing lists of values.
For example, this is used by the predefined Show instance of
the Char type, where values of type String should be shown
in double quotes, rather than between square brackets.

The method readList is provided to allow the programmer to
give a specialised way of parsing lists of values.
For example, this is used by the predefined Read instance of
the Char type, where values of type String should be are
expected to use double quotes, rather than square brackets.

The lex function reads a single lexeme from the input, discarding
initial white space, and returning the characters that constitute the
lexeme. If the input string contains only white space, lex returns a
single successful `lexeme' consisting of the empty string. (Thus
lex "" = [("","")].) If there is no legal lexeme at the
beginning of the input string, lex fails (i.e. returns []).

This lexer is not completely faithful to the Haskell lexical syntax
in the following respects:

Qualified names are not handled properly

Octal and hexadecimal numerics are not recognized as a single token

Comments are not treated properly

Basic Input and output

A value of type IO a is a computation which, when performed,
does some I/O before returning a value of type a.

There is really only one way to "perform" an I/O action: bind it to
Main.main in your program. When your program is run, the I/O will
be performed. It isn't possible to perform I/O from an arbitrary
function, unless that function is itself in the IO monad and called
at some point, directly or indirectly, from Main.main.

IO is a monad, so IO actions can be combined using either the do-notation
or the >> and >>= operations from the Monad class.

The print function outputs a value of any printable type to the
standard output device.
Printable types are those that are instances of class Show; print
converts values to strings for output using the show operation and
adds a newline.

For example, a program to print the first 20 integers and their
powers of 2 could be written as:

The interact function takes a function of type String->String
as its argument. The entire input from the standard input device is
passed to this function as its argument, and the resulting string is
output on the standard output device.

Files

File and directory names are values of type String, whose precise
meaning is operating system dependent. Files can be opened, yielding a
handle which can then be used to operate on the contents of that file.

Exception handling in the I/O monad

The Haskell 98 type for exceptions in the IO monad.
Any I/O operation may raise an IOError instead of returning a result.
For a more general type of exception, including also those that arise
in pure code, see Control.Exception.Exception.