Standard

Operators

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 zipWith ($) fs xs.

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.

Type classes

Instances of Ord can be derived for any user-defined
datatype whose constituent types are in Ord. The declared order
of the constructors in the data declaration determines the ordering
in derived Ord instances. The Ordering datatype allows a single
comparison to determine the precise ordering of two objects.

Minimal complete definition: either compare or <=.
Using compare can be more efficient for complex types.

The Eq class defines equality (==) and inequality (/=).
All the basic datatypes exported by the Prelude are instances of Eq,
and Eq may be derived for any datatype whose constituents are also
instances of Eq.

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.

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:

Derived instances of Show have the following properties, which
are compatible with derived instances of 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 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.

The function decodeFloat applied to a real floating-point
number returns the significand expressed as an Integer and an
appropriately scaled exponent (an Int). If decodeFloat x
yields (m,n), then x is equal in value to m*b^^n, where b
is the floating-point radix, and furthermore, either m and n
are both zero or else b^(d-1) <= abs m < b^d, where d is
the value of floatDigits x.
In particular, decodeFloat 0 = (0,0). If the type
contains a negative zero, also decodeFloat (-0.0) = (0,0).
The result ofdecodeFloat xis unspecified if either ofisNaN xorisInfinite xisTrue.

encodeFloat performs the inverse of decodeFloat in the
sense that for finite x with the exception of -0.0,
uncurryencodeFloat (decodeFloat x) = x.
encodeFloat m n is one of the two closest representable
floating-point numbers to m*b^^n (or ±Infinity if overflow
occurs); usually the closer, but if m contains too many bits,
the result may be rounded in the wrong direction.

The first component of decodeFloat, scaled to lie in the open
interval (-1,1), either 0.0 or of absolute value >= 1/b,
where b is the floating-point radix.
The behaviour is unspecified on infinite or NaN values.

a version of arctangent taking two real floating-point arguments.
For real floating x and y, atan2 y x computes the angle
(from the positive x-axis) of the vector from the origin to the
point (x,y). atan2 y x returns a value in the range [-pi,
pi]. It follows the Common Lisp semantics for the origin when
signed zeroes are supported. atan2 y 1, with y in a type
that is RealFloat, should return the same value as atan y.
A default definition of atan2 is provided, but implementors
can provide a more accurate implementation.

Data types

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 Either type.

Lift a semigroup into Maybe forming a Monoid according to
http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be
turned into a monoid simply by adjoining an element e not in S
and defining e*e = e and e*s = s = s*e for all s ∈ S." Since
there is no "Semigroup" typeclass providing just mappend, we
use Monoid instead.

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 characters), 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 toEnum and fromEnum from the
Enum class respectively (or equivalently ord and chr).

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 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").

Some types can be viewed as a monoid in more than one way,
e.g. both addition and multiplication on numbers.
In such cases we often define newtypes and make those instances
of Monoid, e.g. Sum and Product.

Fold a list using the monoid.
For most types, the default definition for mconcat will be
used, but the function is included in the class definition so
that an optimized version can be provided for specific types.

Lift a semigroup into Maybe forming a Monoid according to
http://en.wikipedia.org/wiki/Monoid: "Any semigroup S may be
turned into a monoid simply by adjoining an element e not in S
and defining e*e = e and e*s = s = s*e for all s ∈ S." Since
there is no "Semigroup" typeclass providing just mappend, we
use Monoid instead.

Maybe

The mapMaybe function is a version of map which can throw
out elements. In particular, the functional argument returns
something of type Maybe b. If this is Nothing, no element
is added on to the result list. If it just Just b, then b is
included in the result list.

Either

Partitions a list of Either into two lists
All the Left elements are extracted, in order, to the first
component of the output. Similarly the Right elements are extracted
to the second component of the output.

Takes a value of type a and returns a concrete representation
of that type. The value of the argument should be ignored by
any instance of Typeable, so that it is safe to pass undefined as
the argument.

When the "acquire" or "release" computations throw exceptions
any monadic side effects in m will be discarded.

When the "in-between" computation throws an exception any
monadic side effects in m produced by that computation will be
discarded but the side effects of the "acquire" or "release"
computations will be retained.

Also, any monadic side effects in m of the "release"
computation will be discarded; it is run only for its side
effects in IO.

Note that when your acquire and release computations are of type IO
it will be more efficient to write:

Print

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: