1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146
|
<title>The Haskell 98 Report: Introduction</title>
<body bgcolor="#ffffff"> <i>The Haskell 98 Report</i><br> <a href="index.html">top</a> | <a href="preface-13.html">back</a> | <a href="lexemes.html">next</a> | <a href="index98.html">contents</a> | <a href="prelude-index.html">function index</a> <br><hr>
<a name="introduction"></a><a name="sect1"></a>
<h2>1<tt> </tt>Introduction</h2>
<p>
Haskell is a general purpose, purely functional
programming language incorporating many recent innovations in
programming language design. Haskell provides
higher-order functions,
non-strict semantics, static polymorphic typing, user-defined
algebraic datatypes, pattern-matching, list comprehensions, a module
system, a monadic I/O system, and a rich set of primitive datatypes,
including lists,
arrays, arbitrary and fixed precision integers, and floating-point
numbers. Haskell is both the culmination
and solidification of many years of research on lazy functional
languages.<p>
This report defines the syntax for Haskell programs and an
informal abstract semantics for the meaning of such
programs.
We leave as implementation
dependent the ways in which Haskell programs are to be
manipulated, interpreted, compiled, etc. This includes such issues as
the nature of programming environments and
the error messages returned for undefined programs
(i.e. programs that formally evaluate to _|_).<a name="programs"></a><p>
<a name="sect1.1"></a>
<h3>1.1<tt> </tt>Program Structure</h3>
<p>
In this section, we describe the abstract syntactic and semantic structure of
Haskell , as well as how it relates to the organization of the
rest of the report.
<OL><LI>At the topmost level a Haskell program is a set
of <I>modules</I>, described in Section <a href="modules.html#modules">5</a>. Modules provide
a way to control namespaces
and to re-use software in large programs.<p>
<LI>The top level of a module consists of a collection of
<I>declarations</I>, of which there are several kinds, all described
in Section <a href="decls.html#declarations">4</a>. Declarations
define things such as ordinary values, datatypes, type
classes, and fixity information.<p>
<LI>At the next lower level are <I>expressions</I>, described
in Section <a href="exps.html#expressions">3</a>. An expression denotes a <I>value
</I>and has a <I>static type</I>; expressions are at the heart of
Haskell programming "in the small."<p>
<LI>At the bottom level is Haskell 's
<I>lexical structure</I>, defined in Section <a href="lexemes.html#lexical-structure">2</a>. The
lexical structure captures the concrete
representation of Haskell programs in text files.<p>
</OL>
This report proceeds bottom-up with respect
to Haskell 's syntactic structure.<p>
The sections not mentioned above are
Section <a href="basic.html#basic-types-and-classes">6</a>, which
describes the standard built-in datatypes and classes in Haskell , and
Section <a href="io-13.html#io">7</a>, which discusses the I/O facility in Haskell
(i.e. how Haskell programs communicate with the outside world).
Also, there are several appendices describing the Prelude,
the concrete syntax, literate programming, the specification of derived
instances, and pragmas supported by most Haskell compilers.<p>
Examples of Haskell program fragments in running text are given
in typewriter font:
<tt><br>
<br>
let x = 1<br>
z = x+y<br>
in z+1<br>
<br>
</tt>"Holes" in program fragments representing arbitrary
pieces of Haskell code are written in italics, as in
<tt>if</tt><I> e</I><sub><I>1</I></sub><I> </I><tt>then</tt><I> e</I><sub><I>2</I></sub><I> </I><tt>else</tt><I> e</I><sub><I>3</I></sub>. Generally the italicized names are
mnemonic, such as <I>e</I> for expressions, <I>d</I> for
declarations, <I>t</I> for types, etc.<a name="intro-kernel"></a><p>
<a name="sect1.2"></a>
<h3>1.2<tt> </tt>The Haskell Kernel</h3>
<p>
Haskell has adopted many of the convenient syntactic structures
that have become popular
in functional programming. In all cases, their formal
semantics can be given via translation into a proper subset of
Haskell called the Haskell <I>kernel</I>. It is
essentially a slightly sugared variant of the lambda calculus with
a straightforward denotational semantics. The translation of each
syntactic structure into the kernel is given as the syntax is
introduced.
This modular design facilitates
reasoning about Haskell programs and provides useful guidelines
for implementors of the language.<a name="errors"></a><p>
<a name="sect1.3"></a>
<h3>1.3<tt> </tt>Values and Types</h3>
<p>
An expression evaluates to a <I>value</I> and has a
static <I>type</I>. Values and types are not mixed in
Haskell .
However, the type system
allows user-defined datatypes of various sorts, and permits not only
parametric polymorphism (using a
traditional Hindley-Milner type structure) but
also <I>ad hoc</I> polymorphism, or <I>overloading</I> (using
<I>type classes</I>).<p>
Errors in Haskell are semantically equivalent to
_|_. Technically, they are not distinguishable
from nontermination, so the language includes no mechanism
for detecting or acting upon errors. Of course, implementations
will probably try to provide useful information about
errors.<a name="namespaces"></a><p>
<a name="sect1.4"></a>
<h3>1.4<tt> </tt>Namespaces</h3>
<p>
Haskell provides a lexical syntax for infix
<I>operators</I> (either functions or constructors). To emphasize
that operators are bound to the same things as identifiers, and to
allow the two to be used interchangeably, there is a simple way to
convert between the two: any function or constructor identifier may be
converted into an operator by enclosing it in backquotes, and any
operator may be converted into an identifier by enclosing it in
parentheses. For example, <tt>x + y</tt> is equivalent to
<tt>(+) x y</tt>, and <tt>f x y</tt> is the same as
<tt>x</tt> `<tt>f</tt>`<tt> y</tt>.
These lexical matters are discussed further in
Section <a href="lexemes.html#lexical-structure">2</a>.<p>
There are six kinds of names in Haskell : those for <I>variables</I> and
<I>constructors</I> denote values; those for <I>type variables</I>,
<I>type constructors</I>, and <I>type classes</I> refer to entities related
to the type system; and <I>module names</I> refer to modules.
There are three constraints on naming:
<OL><LI>Names for variables and type variables are identifiers beginning
with lowercase letters or underscore; the other four kinds of names are
identifiers beginning with uppercase letters.
<LI>Constructor operators are operators beginning with "<tt>:</tt>";
variable operators are operators not beginning with "<tt>:</tt>".
<LI>An identifier must not be used as the name of a type constructor
and a class in the same scope.
</OL>
These are the only constraints; for example,
<tt>Int</tt> may simultaneously be the name of a module, class, and constructor
within a single scope.<p>
<hr><i>The Haskell 98 Report</i><br><a href="index.html">top</a> | <a href="preface-13.html">back</a> | <a href="lexemes.html">next</a> | <a href="index98.html">contents</a> | <a href="prelude-index.html">function index</a> <br><font size=2>1 February, 1999</font>
|