C.2 Introduction

Haskell is named after Haskell B. Curry, the pioneer of the Y combinator in λ-calculus—the mathematical theory of functions on which functional programming is based. Haskell is a useful general-purpose programming language in that it incorporates functional features from Lisp, rule-based programming (i.e., pattern matching) from Prolog, a terse syntax, and data abstraction from Smalltalk and C++. Haskell is a (nearly) pure functional language with some declarative features including pattern-directed invocation, guards, list comprehensions, and mathematical notation. It is an ideal vehicle through which to explore lazy evaluation, type safety, type inference, and currying. The objective here, however, is elementary programming in Haskell. We leave the use of the language to explore concepts to the main text.

This appendix is an example-oriented avenue to get started with Haskell programming and is intended to get a programmer who is already familiar with the essential tenets of functional programming (Chapter 5) writing intermediate programs in Haskell; it is not intended as an exhaustive tutorial or comprehensive reference.

The primary objective of this appendix is to establish an understanding of Haskell programming in readers already familiar with the essential elements of functional programming in preparation for the study of typing and type inference (in Chapter 7), currying and higher-order functions (in Chapter 8), type systems (in Chapter 9), and lazy evaluation (in Chapter 12)—concepts that are both naturally and conveniently explored through Haskell. This appendix should be straightforward for anyone familiar with functional programming in another language, particularly Scheme. We sometimes compare Haskell expressions to their analogs in Scheme.

We use the Glasgow Haskell Compiler (GHC) implementation of Haskell developed at the University of Glasgow in this text. GHC is the state-of-theart implementation of Haskell and compiles Haskell programs to native code on a variety of architectures as well as to C as an intermediate language. In this text, we use GHCi to interpret the Haskell expressions and programs we present. GHCi is the interactive environment of GHC—it provides a read-eval-print loop through which Haskell expressions can be interactively entered and evaluated, and through which entire programs can be interpreted. GHCi is started by entering ghci at the command prompt. Note that Prelude> is the prompt for input in the GHCi Haskell interpreter used in this text. A goal of the functional style of programming is to bring programming closer to mathematics. In this appendix, Haskell and especially its syntax as well as the responses of the Haskell interpreter make the connection between functional programming and mathematics salient.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
18.227.183.153