Programming in Haskell 2nd Edition Graham Hutton instant download
Programming in Haskell 2nd Edition Graham Hutton instant download
pdf download
https://ebookfinal.com/download/programming-in-haskell-2nd-
edition-graham-hutton/
https://ebookfinal.com/download/malaysian-favourites-hutton/
https://ebookfinal.com/download/intertextuality-2nd-edition-graham-
allen/
https://ebookfinal.com/download/haskell-bookcamp-meap-v06-philipp-
hagenlocher/
https://ebookfinal.com/download/programming-in-lua-2nd-edition-
roberto-ierusalimschy/
Clinical Psychology 2nd Edition Graham Davey
https://ebookfinal.com/download/clinical-psychology-2nd-edition-
graham-davey/
https://ebookfinal.com/download/c-programming-in-linux-2nd-edition-
david-haskins/
https://ebookfinal.com/download/in-contradiction-a-study-of-the-
transconsistent-2nd-edition-graham-priest/
https://ebookfinal.com/download/cybercrime-and-digital-deviance-2nd-
edition-graham/
https://ebookfinal.com/download/eu-uk-competition-law-2nd-edition-
cosmo-graham/
Programming in Haskell 2nd Edition Graham Hutton
Digital Instant Download
Author(s): Graham Hutton
ISBN(s): 9781316626221, 1316626229
Edition: 2
File Details: PDF, 8.12 MB
Year: 2016
Language: english
Programming in Haskell
Second Edition
GRAHAM HUTTON
University of Nottingham
University Printing House, Cambridge CB2 8BS, United Kingdom
One Liberty Plaza, 20th Floor, New York, NY 10006, USA
477 Williamstown Road, Port Melbourne, VIC 3207, Australia
4843/24, 2nd Floor, Ansari Road, Daryaganj, Delhi - 110002, India
79 Anson Road, #06-04/06, Singapore 079906
www.cambridge.org
Information on this title: www.cambridge.org/9781316626221
10.1017/9781316784099
© Graham Hutton 2007, 2016
This publication is in copyright. Subject to statutory exception
and to the provisions of relevant collective licensing agreements,
no reproduction of any part may take place without the written
permission of Cambridge University Press.
First published 2007
Second edition 2016
Printed in the United Kingdom by Clays, St Ives plc
A catalogue record for this publication is available from the British Library
ISBN 978-1-316-62622-1 Paperback
Cambridge University Press has no responsibility for the persistence or accuracy
of URLs for external or third-party Internet Web sites referred to in this publication,
and does not guarantee that any content on such Web sites is, or will remain,
accurate or appropriate.
Contents
1 Introduction 3
1.1 Functions 3
1.2 Functional programming 4
1.3 Features of Haskell 6
1.4 Historical background 8
1.5 A taste of Haskell 9
1.6 Chapter remarks 13
1.7 Exercises 13
2 First steps 14
2.1 Glasgow Haskell Compiler 14
2.2 Installing and starting 14
2.3 Standard prelude 15
2.4 Function application 16
2.5 Haskell scripts 17
2.6 Chapter remarks 21
2.7 Exercises 21
3.11 Exercises 36
4 Defining functions 38
4.1 New from old 38
4.2 Conditional expressions 38
4.3 Guarded equations 39
4.4 Pattern matching 40
4.5 Lambda expressions 42
4.6 Operator sections 44
4.7 Chapter remarks 45
4.8 Exercises 45
5 List comprehensions 47
5.1 Basic concepts 47
5.2 Guards 48
5.3 The zip function 50
5.4 String comprehensions 51
5.5 The Caesar cipher 52
5.6 Chapter remarks 56
5.7 Exercises 57
6 Recursive functions 59
6.1 Basic concepts 59
6.2 Recursion on lists 61
6.3 Multiple arguments 63
6.4 Multiple recursion 64
6.5 Mutual recursion 65
6.6 Advice on recursion 66
6.7 Chapter remarks 71
6.8 Exercises 71
7 Higher-order functions 73
7.1 Basic concepts 73
7.2 Processing lists 74
7.3 The foldr function 76
7.4 The foldl function 79
7.5 The composition operator 81
7.6 Binary string transmitter 82
7.7 Voting algorithms 86
7.8 Chapter remarks 89
7.9 Exercises 89
Bibliography 298
Index 300
For Annette, Callum and Tom
Foreword
It is nearly a century ago that Alonzo Church introduced the lambda calculus,
and over half a century ago that John McCarthy introduced Lisp, the world’s
second oldest programming language and the first functional language based
on the lambda calculus. By now, every major programming language including
JavaScript, C++, Swift, Python, PHP, Visual Basic, Java, . . . has support for
lambda expressions or anonymous higher-order functions.
As with any idea that becomes mainstream, inevitably the underlying founda-
tions and principles get watered down or forgotten. Lisp allowed mutation, yet
today many confuse functions as first-class citizens with immutability. At the
same time, other effects such as exceptions, reflection, communication with the
outside world, and concurrency go unmentioned. Adding recursion in the form
of feedback-loops to pure combinational circuits lets us implement mutable state
via flip-flops. Similarly, using one effect such as concurrency or input/output we
can simulate other effects such as mutability. John Hughes famously stated in
his classic paper Why Functional Programming Matters that we cannot make
a language more powerful by eliminating features. To that, we add that often
we cannot even make a language less powerful by removing features. In this
book, Graham demonstrates convincingly that the true value of functional pro-
gramming lies in leveraging first-class functions to achieve compositionality and
equational reasoning. Or in Graham’s own words, “functional programming can
be viewed as a style of programming in which the basic method of computation
is the application of functions to arguments”. These functions do not necessarily
have to be pure or statically typed in order to realise the simplicity, elegance,
and conciseness of expression that we get from the functional style.
While you can code like a functional hacker in a plethora of languages, a
semantically pure and lazy, and syntactically lean and terse language such as
Haskell is still the best way to learn how to think like a fundamentalist. Based
upon decades of teaching experience, and backed by an impressive stream of re-
search papers, in this book Graham gently guides us through the whole gambit of
key functional programming concepts such as higher-order functions, recursion,
list comprehensions, algebraic datatypes and pattern matching. The book does
not shy away from more advanced concepts. If you are still confused by the n-th
blog post that attempts to explain monads, you are in the right place. Gently
starting with the IO monad, Graham progresses from functors to applicatives
using many concrete examples. By the time he arrives at monads, every reader
will feel that they themselves could have come up with the concept of a monad as
a generic pattern for composing functions with effects. The chapter on monadic
xiv Foreword
Erik Meijer
Preface
How is it structured?
The book is divided into two parts. Part I introduces the basic concepts of pure
programming in Haskell and is structured around the core features of the lan-
guage, such as types, functions, list comprehensions, recursion and higher-order
functions. Part II covers impure programming and a range of more advanced
topics, such as monads, parsing, foldable types, lazy evaluation and reasoning
about programs. The book contains many extended programming examples, and
each chapter includes suggestions for further reading and a series of exercises.
The appendices provide solutions to selected exercises, and a summary of some
of the most commonly used definitions from the Haskell standard prelude.
Acknowledgements
I am grateful to the University of Nottingham for providing a sabbatical to pro-
duce this new edition; Thorsten Altenkirch, Venanzio Capretta, Henrik Nilsson
and other members of the FP lab for our many enjoyable discussions; Iván Pérez
Domı́nguez for useful comments on a number of chapters; the students and tutors
on all of my Haskell courses for their feedback; Clare Dennison, David Tranah
and Abigail Walkington at CUP for their editorial work; the GHC team for pro-
ducing such a great compiler; and finally, Catherine and Ian Hutton for getting
me started in computing all those years ago.
Many thanks also to Ki Yung Ahn, Bob Davison, Philip Hölzenspies and Neil
Mitchell for providing detailed comments on the first edition, and to the following
for pointing our errors and typos: Paul Brown, Sergio Queiroz de Medeiros,
David Duke, Robert Fabian, Ben Fleis, Robert Furber, Andrew Kish, Tomoyas
Kobayashi, Florian Larysch, Carlos Oroz, Douglas Philips, Bruce Turner, Gregor
Ulm, Marco Valtorta and Kazu Yamamoto. All of these comments have been
taken into account when preparing the new edition.
Graham Hutton
Part I
Basic Concepts
1 Introduction
In this chapter we set the stage for the rest of the book. We start by reviewing
the notion of a function, then introduce the concept of functional programming,
summarise the main features of Haskell and its historical background, and con-
clude with three small examples that give a taste of Haskell.
1.1 Functions
In Haskell, a function is a mapping that takes one or more arguments and pro-
duces a single result, and is defined using an equation that gives a name for the
function, a name for each of its arguments, and a body that specifies how the
result can be calculated in terms of the arguments.
For example, a function double that takes a number x as its argument, and
produces the result x + x, can be defined by the following equation:
double x = x + x
When a function is applied to actual arguments, the result is obtained by sub-
stituting these arguments into the body of the function in place of the argument
names. This process may immediately produce a result that cannot be further
simplified, such as a number. More commonly, however, the result will be an
expression containing other function applications, which must then be processed
in the same way to produce the final result.
For example, the result of the application double 3 of the function double to
the number 3 can be determined by the following calculation, in which each step
is explained by a short comment in curly parentheses:
double 3
“ t applying double u
3 + 3
“ t applying + u
6
Similarly, the result of the nested application double (double 2) in which the
function double is applied twice can be calculated as follows:
double (double 2)
4 Introduction
Alternatively, the same result can also be calculated by starting with the outer
application of the function double rather than the inner:
double (double 2)
“ t applying the outer double u
double 2 + double 2
“ t applying the first double u
(2 + 2) + double 2
“ t applying the first + u
4 + double 2
“ t applying double u
4 + (2 + 2)
“ t applying the second + u
4 + 4
“ t applying + u
8
However, this approach requires two more steps than our original version, because
the expression double 2 is duplicated in the first step and hence simplified twice.
In general, the order in which functions are applied in a calculation does not affect
the value of the final result, but it may affect the number of steps required, and
whether the calculation process terminates. These issues are explored in more
detail when we consider how expressions are evaluated in chapter 15.
Language: English
REAL LIFE;
WITH
CONVERSATIONS,
CALCULATED TO
BY
MARY WOLLSTONECRAFT.
A NEW EDITION.
LONDON:
1796
PREFACE.
C H A P . II.
C H A P . III.
C H A P . IV.
C H A P . V.
C H A P . VI.
C H A P . VII.
Virtue the Soul of Beauty.—The Tulip and the Rose.—The
Nightingale.—External Ornaments.—Characters. 47
C H A P . VIII.
C H A P . IX.
C H A P . X.
C H A P . XI.
C H A P . XII.
C H A P . XIII.
C H A P . XV.
C H A P . XVI.
C H A P . XVII.
C H A P . XVIII.
C H A P . XIX.
C H A P . XX.
Visit to Mrs. Trueman.—The Use of Accomplishments.—Virtue the
Soul of All. 131
C H A P . XXI.
C H A P . XXII.
C H A P . XXIII.
C H A P . XXIV.
C H A P . XXV.
STORIES.
CHAP. I.
The Treatment of Animals.—The Ant.—The
Bee.—Goodness.—The Lark’s Nest.—The
Asses.
Our website is not just a platform for buying books, but a bridge
connecting readers to the timeless values of culture and wisdom. With
an elegant, user-friendly interface and an intelligent search system,
we are committed to providing a quick and convenient shopping
experience. Additionally, our special promotions and home delivery
services ensure that you save time and fully enjoy the joy of reading.
ebookfinal.com