The Haskell 98 Report
top | back | next | contents | function index

1  Introduction

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.

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

1.1  Program Structure

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.

  1. At the topmost level a Haskell program is a set of modules, described in Section 5. Modules provide a way to control namespaces and to re-use software in large programs.

  2. The top level of a module consists of a collection of declarations, of which there are several kinds, all described in Section 4. Declarations define things such as ordinary values, datatypes, type classes, and fixity information.

  3. At the next lower level are expressions, described in Section 3. An expression denotes a value and has a static type; expressions are at the heart of Haskell programming "in the small."

  4. At the bottom level is Haskell 's lexical structure, defined in Section 2. The lexical structure captures the concrete representation of Haskell programs in text files.

This report proceeds bottom-up with respect to Haskell 's syntactic structure.

The sections not mentioned above are Section 6, which describes the standard built-in datatypes and classes in Haskell , and Section 7, 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.

Examples of Haskell program fragments in running text are given in typewriter font:

 let x = 1
     z = x+y
 in  z+1

"Holes" in program fragments representing arbitrary pieces of Haskell code are written in italics, as in if e1 then e2 else e3. Generally the italicized names are mnemonic, such as e for expressions, d for declarations, t for types, etc.

1.2  The Haskell Kernel

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 kernel. 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.

1.3  Values and Types

An expression evaluates to a value and has a static type. 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 ad hoc polymorphism, or overloading (using type classes).

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.

1.4  Namespaces

Haskell provides a lexical syntax for infix operators (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, x + y is equivalent to (+) x y, and f x y is the same as x `f` y. These lexical matters are discussed further in Section 2.

There are six kinds of names in Haskell : those for variables and constructors denote values; those for type variables, type constructors, and type classes refer to entities related to the type system; and module names refer to modules. There are three constraints on naming:

  1. 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.
  2. Constructor operators are operators beginning with ":"; variable operators are operators not beginning with ":".
  3. An identifier must not be used as the name of a type constructor and a class in the same scope.
These are the only constraints; for example, Int may simultaneously be the name of a module, class, and constructor within a single scope.


The Haskell 98 Report
top | back | next | contents | function index
1 February, 1999