Beginning Haskell (eBook)

A Project-Based Approach
eBook Download: PDF
2014 | 1st ed.
XX, 428 Seiten
Apress (Verlag)
978-1-4302-6251-0 (ISBN)

Lese- und Medienproben

Beginning Haskell -  Alejandro Serrano Mena
Systemvoraussetzungen
52,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Beginning Haskell provides a broad-based introduction to the Haskell language, its libraries and environment, and to the functional programming paradigm that is fast growing in importance in the software industry. The book takes a project-based approach to learning the language that is unified around the building of a web-based storefront. Excellent coverage is given to the Haskell ecosystem and supporting tools. These include the Cabal build tool for managing projects and modules, the HUnit and QuickCheck tools for software testing, the Scotty framework for developing web applications, Persistent and Esqueleto for database access, and also parallel and distributed programming libraries.

Functional programming is gathering momentum, allowing programmers to express themselves in a more concise way, reducing boilerplate and increasing the safety of code. Indeed, mainstream languages such as C# and Java are adopting features from functional programming, and from languages implementing that paradigm. Haskell is an elegant and noise-free pure functional language with a long history, having a huge number of library contributors and an active community. This makes Haskell the best tool for both learning and applying functional programming, and Beginning Haskell the perfect book to show off the language and what it can do.

  • Takes you through a series of projects showing the different parts of the language.
  • Provides an overview of the most important libraries and tools in the Haskell ecosystem.
  • Teaches you how to apply functional patterns in real-world scenarios.


Alejandro Serrano Mena is working towards his PhD thesis inthe Software Technology group in Utrecht University. He is passionate forfunctional programming, and has been coding Haskell for personal andprofessional projects for more than five years. During his college years he wasactive in an association promoting functional languages among students, givingtalks and helping programmers get started in the functional paradigm. In 2011he took part in the Google Summer of Code program, enhancing the Haskellplug-in for the popular development environment Eclipse. His current positioninvolves research for enhancing the way in which developers get feedback andinteract with strong type systems such as Haskell's.
Beginning Haskell provides a broad-based introduction to the Haskell language, its libraries and environment, and to the functional programming paradigm that is fast growing in importance in the software industry. The book takes a project-based approach to learning the language that is unified around the building of a web-based storefront. Excellent coverage is given to the Haskell ecosystem and supporting tools. These include the Cabal build tool for managing projects and modules, the HUnit and QuickCheck tools for software testing, the Scotty framework for developing web applications, Persistent and Esqueleto for database access, and also parallel and distributed programming libraries. Functional programming is gathering momentum, allowing programmers to express themselves in a more concise way, reducing boilerplate and increasing the safety of code. Indeed, mainstream languages such as C# and Java are adopting features from functional programming, and from languages implementing that paradigm. Haskell is an elegant and noise-free pure functional language with a long history, having a huge number of library contributors and an active community. This makes Haskell the best tool for both learning and applying functional programming, and Beginning Haskell the perfect book to show off the language and what it can do. Takes you through a series of projects showing the different parts of the language. Provides an overview of the most important libraries and tools in the Haskell ecosystem. Teaches you how to apply functional patterns in real-world scenarios.

Alejandro Serrano Mena is working towards his PhD thesis inthe Software Technology group in Utrecht University. He is passionate forfunctional programming, and has been coding Haskell for personal andprofessional projects for more than five years. During his college years he wasactive in an association promoting functional languages among students, givingtalks and helping programmers get started in the functional paradigm. In 2011he took part in the Google Summer of Code program, enhancing the Haskellplug-in for the popular development environment Eclipse. His current positioninvolves research for enhancing the way in which developers get feedback andinteract with strong type systems such as Haskell's.

Contents at a Glance 3
Contents 397
About the Author 407
About the Technical Reviewer 408
Acknowledgments 409
Introduction 5
Part 1: First Steps 6
Chapter 1: Going Functional 7
Why Haskell? 7
Why Pure Functional Programming? 8
Why Strong Static Typing? 9
The Haskell Ecosystem 10
The History of Haskell 10
Your Working Environment 10
Installing on Windows 11
Installing on Mac OS X 11
Installing on Linux 12
Installing on Linux from Source 12
Checking That the Installation Is Successful 13
Installing EclipseFP 13
Taking Your First Steps with GHCi 15
The Time Machine Store 16
Summary 17
Chapter 2: Declaring the Data Model 18
Working with Characters, Numbers, and Lists 18
Characters 18
Numbers 20
Strings 21
Lists 21
List Operations 22
Creating a New Project 25
Creating a Project from the Command Line 25
Creating a Project from EclipseFP 25
Understanding Modules 28
Defining Simple Functions 29
Creating a Simple Function 29
Specifying the Function’s Type 30
Developing a Robust Example 30
Returning More Than One Value 32
Working with Data Types 33
Pattern Matching 36
Simple Patterns 36
Lists and Tuples 40
Guards 41
View Patterns 43
Records 44
Creation and Use 44
The Default Values Idiom 46
Summary 48
Chapter 3: Reusing Code Through Lists 49
Parametric Polymorphism 49
Functions As Parameters 52
Higher-Order Functions 52
Anonymous Functions 54
Partial Application of a Function 56
More on Modules 59
Module Imports 59
Smart Constructors and Views 61
Diving into Lists 63
Folds 63
Lists and Predicates 66
Lists Containing Tuples 71
List Comprehensions 72
Haskell Origami 75
Summary 78
Chapter 4: Using Containers and Type Classes 79
Using Packages 79
Managing Packages with Cabal and EclipseFP 79
Sandboxed Environments 84
Containers: Maps, Sets, Trees, Graphs 86
Maps 86
Sets 89
Trees 91
Graphs 92
Obtaining Help 94
Ad Hoc Polymorphism: Type Classes 96
Declaring Classes and Instances 96
Built-in Type Classes 99
Binary Tress for the Minimum Price 103
Step 1: Simple Binary Trees 103
Step 2: Polymorphic Binary Trees 104
Step 3: Binary Trees with Monoidal Cache 106
Container-Related Type Classes 108
Functors 108
Foldables 109
Summary 111
Chapter 5: Laziness and Infinite Structures 112
An Infinite Number of Time Machines 112
Lazy Evaluation Model 116
Understanding Evaluation in Haskell 116
Problems with Laziness 120
Pattern Matching and Laziness 122
Profiling with GHC 123
Strictness Annotations 128
Summary 130
Part 2: Data Mining 131
Chapter 6: Knowing Your Clients Using Monads 132
Data Mining 132
Implementing K-means 133
Lenses 137
Discovering Monads 143
Watching Out for Incomplete Data 143
Combinators for State 145
Dissecting the Combinators 147
do Notation 149
Monad Laws 152
Different Sorts of State 153
State and Lenses 153
Reader, Writer, and RWS 154
Mutable References with ST 158
Summary 159
Chapter 7: More Monads: Now for Recommendations 160
Returning More Than One Value 160
The List Monad 161
A New View Over Monads 162
Failures and Alternatives 163
Association Rules Learning 166
Flattening Values into Transactions 166
The Apriori Algorithm 168
Search Problems 171
Paths in a Graph 171
The Logic Monad 172
Monads and Lists Redux 174
Combining Values Under a Monad 174
Monad Comprehensions 177
Combining Monads 179
Monad Transformers 179
Monad Classes 182
Summary 184
Chapter 8: Working in Several Cores 185
Parallelism, Concurrency, and Distribution 185
The Par Monad 186
Futures 186
Dataflow Parallelism with IVars 188
Parallelizing the Apriori Algorithm 190
Software Transactional Memory 192
Concurrent Use of Resources 192
Atomic Transactions 194
Rolling Back Transactions 195
Producer-Consumer Queues 197
Cloud Haskell 198
Looking for Galaxies 198
Looking for Typed Galaxies 202
Extra Features 203
Summary 203
Part 3: Resource Handling 204
Chapter 9: Dealing with Files: IO and Conduit 205
Basic Input and Output 205
Randomness 209
Working with Files 211
Reading and Writing 211
Handling Files 213
Error Handling 214
Pure Errors 214
Catching Exceptions 217
Throwing Exceptions 220
Streaming Data with Conduit 221
Problems with Lazy Input/Output 221
Introducing Conduits 222
Accessing Files via Conduit 226
Looking Further Than Text Files 227
Basic Networking 227
Binary Serialization 229
Summary 230
Chapter 10: Building and Parsing Text 231
The Five Textual Data Types 231
Building as Fast as the Wind 235
Parsing with attoparsec 237
Introducing New Type Classes 242
Applicative 242
Functors, Applicatives, and Monads 244
Alternative 246
Traversable 247
Don’t Overengineer: Just Use JSON 249
Summary 254
Chapter 11: Safe Database Access 255
Database Access Landscape 255
Abstracting Over Several DBMSs 256
Introducing Persistent and Esqueleto 256
Connection 257
Schemas and Migrations 258
Describing the Entities 259
Creating the Database 262
Queries 265
Queries by Identifier or Uniqueness 265
Selecting Several Entities 266
SQL Queries with Esqueleto 267
Insertions, Updates, and Deletions 270
Summary 272
Chapter 12: Web Applications 273
Haskell Web Ecosystem 273
Web Frameworks 273
Compilation to JavaScript 275
RESTful Structure 275
Back End with Scotty 276
Simple Skeleton 276
Showing Products from the Database 277
Inserting New Products Using Forms 281
Front End with Fay 285
Foreign Function Interface 286
Fay and jQuery 287
Summary 290
Part 4: Domain Specific Languages 291
Chapter 13: Strong Types for Describing Offers 292
Domain-Specific Languages 292
Embedding Your Language in Haskell 293
The Offers Language 294
Adding Safety to the Expression Language 296
Dependent Typing 299
Introducing Idris 300
Enforcing the Presents Rule in Idris 303
Type-Level Programming in Haskell 304
Two Styles of Programming 305
Representing Natural Numbers 305
Functional Dependencies 307
Categories of Products with FDs 307
Enforcing the Presents Rule with FDs 309
Type Families 312
Enforcing the Presents Rule with TFs 312
Categories of Products with TFs 314
Data Type Promotion and Singletons 318
A Further Refinement to the Presents Rule 318
Enforcing the Duration Rule 321
Summary 325
Chapter 14: Interpreting Offers with Attributes 327
Interpretations and Attribute Grammars 327
A Simple Interpretation 327
Introducing Attribute Grammars 328
Your First Attribute Grammar 329
Synthesizing the Result 329
Executing the Attribute Grammar 330
Integrating UUAGC in Your Package 331
Installing UUAGC 331
UUAGC and Cabal 332
Expressions Interpretation 334
Using an Attribute Grammar 334
Precomputing Some Values 336
A Different (Monadic) View 337
Offer Interpretations 339
Checking the Presents Rule 339
Showing an HTML Description 340
Origami Programming Over Any Data Type 344
Summary 346
Part 5: Engineering the Store 347
Chapter 15: Documenting, Testing, and Verifying 348
Documenting Binary Trees with Haddock 348
Unit Testing with HUnit 352
Declaring Tests in Cabal 352
Writing Unit Tests 354
Randomized Testing with QuickCheck 357
Testing List Properties 357
Testing Binary Tree Properties 358
Formal Verification with Idris 360
Summary 364
Chapter 16: Architecting Your Application 365
Design Patterns and Functional Programming 365
Medium-Level Guidelines 366
Use Higher-Order Combinators 366
Refactor 367
Use Type Classes Wisely 367
Enforce Invariants via the Type System 367
Stay (as) Pure and Polymorphic (as Possible) 367
Tools 368
Project and Dependency Management 368
Code Style 368
Documentation 369
Test and Verification 369
Benchmarking 369
Profiling 369
Coverage 369
Remote Monitoring 370
Projects 370
Data Mining Library 370
Store Network Client 371
Administration Interface and Tetris 376
Roll Your Own Monad 377
Summary 379
Appendix A: Looking Further 380
Haskell Resources 380
Other Functional Languages 381
Appendix B: Time Traveling with Haskell 382
Index 384

Erscheint lt. Verlag 5.3.2014
Zusatzinfo XX, 428 p. 44 illus.
Verlagsort Berkeley
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
ISBN-10 1-4302-6251-6 / 1430262516
ISBN-13 978-1-4302-6251-0 / 9781430262510
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 4,6 MB

DRM: Digitales Wasserzeichen
Dieses eBook enthält ein digitales Wasser­zeichen und ist damit für Sie persona­lisiert. Bei einer missbräuch­lichen Weiter­gabe des eBooks an Dritte ist eine Rück­ver­folgung an die Quelle möglich.

Dateiformat: PDF (Portable Document Format)
Mit einem festen Seiten­layout eignet sich die PDF besonders für Fach­bücher mit Spalten, Tabellen und Abbild­ungen. Eine PDF kann auf fast allen Geräten ange­zeigt werden, ist aber für kleine Displays (Smart­phone, eReader) nur einge­schränkt geeignet.

Systemvoraussetzungen:
PC/Mac: Mit einem PC oder Mac können Sie dieses eBook lesen. Sie benötigen dafür einen PDF-Viewer - z.B. den Adobe Reader oder Adobe Digital Editions.
eReader: Dieses eBook kann mit (fast) allen eBook-Readern gelesen werden. Mit dem amazon-Kindle ist es aber nicht kompatibel.
Smartphone/Tablet: Egal ob Apple oder Android, dieses eBook können Sie lesen. Sie benötigen dafür einen PDF-Viewer - z.B. die kostenlose Adobe Digital Editions-App.

Zusätzliches Feature: Online Lesen
Dieses eBook können Sie zusätzlich zum Download auch online im Webbrowser lesen.

Buying eBooks from abroad
For tax law reasons we can sell eBooks just within Germany and Switzerland. Regrettably we cannot fulfill eBook-orders from other countries.

Mehr entdecken
aus dem Bereich
Entwicklung von GUIs für verschiedene Betriebssysteme

von Achim Lingott

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
39,99
Das umfassende Handbuch

von Johannes Ernesti; Peter Kaiser

eBook Download (2023)
Rheinwerk Computing (Verlag)
44,90
Mit über 150 Workouts in Java und Python

von Luigi Lo Iacono; Stephan Wiefling; Michael Schneider

eBook Download (2023)
Carl Hanser Verlag GmbH & Co. KG
29,99