Practical Haskell - Alejandro Serrano Mena

Practical Haskell (eBook)

A Real World Guide to Programming
eBook Download: PDF
2019 | 2nd ed.
XXII, 595 Seiten
Apress (Verlag)
978-1-4842-4480-7 (ISBN)
Systemvoraussetzungen
46,99 inkl. MwSt
  • Download sofort lieferbar
  • Zahlungsarten anzeigen

Get a practical, hands-on 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. This book contains excellent coverage of the Haskell ecosystem and supporting tools, include Cabal and Stack for managing projects, HUnit and QuickCheck for software testing, the Spock framework for developing web applications, Persistent and Esqueleto for database access, and parallel and distributed programming libraries.

You'll see how functional programming is gathering momentum, allowing you to express yourself in a more concise way, reducing boilerplate, and increasing the safety of your code. 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 Practical Haskell takes advantage of this to show off the language and what it can do.

What You Will Learn

  • Get started programming with Haskell
  • Examine the different parts of the language
  • Gain an overview of the most important libraries and tools in the Haskell ecosystem
  • Apply functional patterns in real-world scenarios
  • Understand monads and monad transformers
  • Proficiently use laziness and resource management

Who This Book Is For

Experienced programmers who may be new to the Haskell programming language. However, some prior exposure to Haskell is recommended. 




Alejandro Serrano Mena is working towards his PhD thesis in the Software Technology group in Utrecht University. He is passionate about functional programming, and has been coding Haskell for personal and professional projects for more than five years. During his college years he was active in an association promoting functional languages among students, giving talks and helping programmers get started in the functional paradigm. In 2011 he took part in the Google Summer of Code program, enhancing the Haskell plug-in for the popular development environment Eclipse. His current position involves research for enhancing the way in which developers get feedback and interact with strong type systems such as Haskell's.
Get a practical, hands-on 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. This book contains excellent coverage of the Haskell ecosystem and supporting tools, include Cabal and Stack for managing projects, HUnit and QuickCheck for software testing, the Spock framework for developing web applications, Persistent and Esqueleto for database access, and parallel and distributed programming libraries.You'll see how functional programming is gathering momentum, allowing you to express yourself in a more concise way, reducing boilerplate, and increasing the safety of your code. 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 Practical Haskell takes advantage of this to show off the language and what it can do.What You Will LearnGet started programming with HaskellExamine the different parts of the languageGain an overview of the most important libraries and tools in the Haskell ecosystemApply functional patterns in real-world scenariosUnderstand monads and monad transformersProficiently use laziness and resource managementWho This Book Is ForExperienced programmers who may be new to the Haskell programming language. However, some prior exposure to Haskell is recommended. 

Table of Contents 5
About the Author 15
About the Technical Reviewer 16
Acknowledgments 17
Introduction 18
Part I: First Steps 20
Chapter 1: Going Functional 21
Why Haskell? 21
Why Pure Functional Programming? 22
Why Strong Static Typing? 24
The Haskell Ecosystem 25
The History of Haskell 26
Your Working Environment 26
Installing on Windows or Mac OS X 27
Installing on Linux 27
Installing on Linux from Source 28
First Steps with GHCi 29
The Time Machine Store 31
Summary 32
Chapter 2: Declaring the Data Model 34
Characters, Numbers, and Lists 34
Characters 35
Numbers 36
Strings 38
Lists 39
Creating a New Project 44
Creating a Project with Cabal 44
Creating a Project with Stack 46
Understanding Modules 48
Cabal and Stack 50
Defining Simple Functions 50
Creating a Simple Function 51
Specifying the Function’s Type 51
Developing a Robust Example 52
Returning More Than One Value 55
Working with Data Types 57
Pattern Matching 61
Simple Patterns 61
Lists and Tuples 66
Guards 68
View Patterns 71
Records 73
Creation and Use 73
The Default Values Idiom 77
Summary 79
Chapter 3: Increasing Code Reuse 80
Parametric Polymorphism 81
Functions As Parameters 84
Higher-Order Functions 85
Anonymous Functions 87
Partial Application of a Function 90
More on Modules 94
Module Imports 94
Smart Constructors and Views 96
Diving into Lists 99
Folds 100
Lists and Predicates 104
Lists Containing Tuples 112
List Comprehensions 113
Haskell Origami 118
Summary 123
Chapter 4: Using Containers and Type Classes 125
Using Packages 126
Managing Dependencies 127
Building Packages 129
Building Packages with Cabal 129
Building Packages with Stack 131
Obtaining Help 134
Containers: Maps, Sets, Trees, Graphs 134
Maps 135
Sets 140
Trees 142
Graphs 145
Ad Hoc Polymorphism: Type Classes 148
Declaring Classes and Instances 149
Built-in Type Classes 153
Binary Trees for the Minimum Price 159
Step 1: Simple Binary Trees 159
Step 2: Polymorphic Binary Trees 161
Step 3: Binary Trees with Monoidal Cache 163
Container-Related Type Classes 166
Functors 166
Foldables 169
Summary 171
Chapter 5: Laziness and Infinite Structures 172
An Infinite Number of Time Machines 173
Lazy Evaluation Model 178
Understanding Evaluation in Haskell 178
Problems with Laziness 183
Pattern Matching and Laziness 186
Profiling with GHC 188
Strictness Annotations 194
Summary 197
Part II: Data Mining 198
Chapter 6: Knowing Your Clients Using Monads 199
Data Mining 200
Implementing K-means 200
Lenses 207
Discovering Monads 216
Watching Out for Incomplete Data 216
Combinators for State 219
Dissecting the Combinators 223
do Notation 226
Monad Laws 230
Different Sorts of State 231
State and Lenses 232
Reader, Writer, and RWS 234
Mutable References with ST 238
Summary 241
Chapter 7: More Monads: Now for Recommendations 242
Returning More Than One Value 243
The List Monad 243
A New View Over Monads 245
Failures and Alternatives 246
Association Rules Learning 250
Flattening Values into Transactions 251
The Apriori Algorithm 254
Search Problems 260
Paths in a Graph 260
The Logic Monad 262
Monads and Lists Redux 265
Combining Values Under a Monad 265
Monad Comprehensions 269
Combining Monads 272
Monad Transformers 273
Monad Classes 278
Summary 281
Chapter 8: Working in Several Cores 282
Parallelism, Concurrency, and Distribution 282
The Par Monad 284
Futures 284
Dataflow Parallelism with IVars 287
Parallelizing the Apriori Algorithm 289
Software Transactional Memory 292
Concurrent Use of Resources 293
Atomic Transactions 295
Rolling Back Transactions 299
Producer-Consumer Queues 301
Single-Process Queues 301
Message Queues Using AMQP 303
AMQP in Haskell 306
Summary 309
Part III: Resource Handling 311
Chapter 9: Dealing with Files: IO and Conduit 312
Basic Input and Output 313
Randomness 318
Working with Files 321
Reading and Writing 321
Handling Files 325
Error Handling 327
Pure Errors 327
Catching Exceptions 330
Throwing Exceptions 335
Streaming Data with Conduit 337
Problems with Lazy Input/Output 337
Introducing Conduits 339
Accessing Files via Conduit 343
Looking Further Than Text Files 346
Basic Networking 346
Binary Serialization 348
Comma-Separated Values 350
Summary 352
Chapter 10: Building and Parsing Text 354
The Five Textual Data Types 354
Building as Fast as the Wind 360
Parsing with attoparsec 364
Introducing New Type Classes 371
Applicative 372
Functors, Applicatives, and Monads 374
Alternative 377
Traversable 378
Don’t Overengineer: Just Use JSON 381
Summary 389
Chapter 11: Safe Database Access 390
Database Access Landscape 390
Abstracting Over Several DBMSs 391
Introducing Persistent and Esqueleto 392
Connection 393
Schemas and Migrations 396
Describing the Entities 397
Creating the Database 402
Queries 406
Queries by Identifier or Uniqueness 406
Selecting Several Entities 408
SQL Queries with Esqueleto 411
Insertions, Updates, and Deletions 415
Summary 419
Chapter 12: Web Applications 420
Haskell Web Ecosystem 420
Web Frameworks 421
Compilation to JavaScript 423
RESTful Structure 425
Back End with Spock 426
Simple Skeleton 426
Showing Products from the Database 428
Inserting New Products Using Forms 434
Front End with Elm 439
Retrieving Products 443
Summary 448
Part IV: Domain Specific Languages 449
Chapter 13: Strong Types for Describing Offers 450
Domain-Specific Languages 450
Embedding Your Language in Haskell 451
The Offers Language 454
Adding Safety to the Expression Language 457
Type-Level Programming 461
Two Styles of Programming 463
Representing Natural Numbers 464
Functional Dependencies 466
Categories of Products with FDs 466
Vectors Using FDs 470
Enforcing the Presents Rule with FDs 473
Type Families 475
Vectors Using TFs 475
Enforcing the Presents Rule with TFs 477
Categories of Products with TFs 478
Data Type Promotion and Singletons 483
A Further Refinement to the Presents Rule 483
Cooking with Singletons 486
Enforcing the Duration Rule 487
Summary 494
Chapter 14: Interpreting Offers with Attributes 496
Interpretations and Attribute Grammars 497
A Simple Interpretation 497
Introducing Attribute Grammars 497
Your First Attribute Grammar 500
Synthesizing the Result 500
Executing the Attribute Grammar 503
Integrating UUAGC in Your Package 504
Expressions Interpretation 507
Using an Attribute Grammar 507
Precomputing Some Values 510
A Different (Monadic) View 512
Offer Interpretations 514
Checking the Presents Rule 514
Showing an HTML Description 516
Programming with Data Types 522
Origami Programming Over Any Data Type 522
Data Type-Generic Programming 525
Summary 529
Part V: Engineering the Store 531
Chapter 15: Documenting, Testing, and Verifying 532
Documenting Binary Trees with Haddock 533
Unit Testing with HUnit 537
Declaring Tests in Cabal 538
Writing Unit Tests 539
Randomized Testing with QuickCheck 543
Testing List Properties 544
Testing Binary Tree Properties 545
Formal Verification with LiquidHaskell 548
Describing Binary Search Trees 551
Summary 553
Chapter 16: Architecting Your Application 554
Tools 554
Project and Dependency Management 555
Code Style 555
Documentation 556
Test and Verification 556
Benchmarking 556
Profiling 557
Coverage 557
Remote Monitoring 557
Design Patterns and Functional Programming 558
Medium-Level Guidelines 560
Use Higher-Order Combinators 560
Refactor 560
Use Type Classes Wisely 560
Enforce Invariants via the Type System 561
Stay (As) Pure and Polymorphic (As Possible) 561
Patterns with Monads 562
Summary of Monads 562
Restrictive Monad Classes 568
Roll Your Own Monad 569
Summary 572
Chapter 17: Looking Further 573
Projects 573
Data Mining Library 574
Store Network Client 576
Administration Interface and Tetris 577
Additional Haskell Resources 579
Other Functional Languages 580
Appendix: Time Travelling with Haskell 581
Index 584

Erscheint lt. Verlag 27.4.2019
Zusatzinfo XXII, 595 p. 31 illus., 3 illus. in color.
Sprache englisch
Themenwelt Mathematik / Informatik Informatik Programmiersprachen / -werkzeuge
Mathematik / Informatik Informatik Software Entwicklung
Schlagworte Basics • Code • Development • Functional • fundamentals • Haskell • language • Practical • programming • real world • Software • source
ISBN-10 1-4842-4480-X / 148424480X
ISBN-13 978-1-4842-4480-7 / 9781484244807
Haben Sie eine Frage zum Produkt?
PDFPDF (Wasserzeichen)
Größe: 6,2 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
Das umfassende Handbuch

von Johannes Ernesti; Peter Kaiser

eBook Download (2023)
Rheinwerk Computing (Verlag)
31,43
Das Handbuch für Webentwickler

von Philip Ackermann

eBook Download (2023)
Rheinwerk Computing (Verlag)
34,93
Deterministische und randomisierte Algorithmen

von Volker Turau; Christoph Weyer

eBook Download (2024)
De Gruyter (Verlag)
64,95