Serrano Mena Beginning Haskell
1. Auflage 2014
ISBN: 978-1-4302-6251-0
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark
A Project-Based Approach
E-Book, Englisch, 409 Seiten, eBook
ISBN: 978-1-4302-6251-0
Verlag: APRESS
Format: PDF
Kopierschutz: 1 - PDF Watermark
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.
Zielgruppe
Popular/general
Autoren/Hrsg.
Weitere Infos & Material
1;Contents at a Glance;3
2;Contents;397
3;About the Author;407
4;About the Technical Reviewer;408
5;Acknowledgments;409
6;Introduction;5
7;Part 1: First Steps;6
7.1;Chapter 1: Going Functional;7
7.1.1;Why Haskell?;7
7.1.1.1;Why Pure Functional Programming?;8
7.1.1.2;Why Strong Static Typing?;9
7.1.1.3;The Haskell Ecosystem;10
7.1.2;The History of Haskell;10
7.1.3;Your Working Environment;10
7.1.3.1;Installing on Windows;11
7.1.3.2;Installing on Mac OS X;11
7.1.3.3;Installing on Linux;12
7.1.3.4;Installing on Linux from Source;12
7.1.3.5;Checking That the Installation Is Successful;13
7.1.3.6;Installing EclipseFP;13
7.1.4;Taking Your First Steps with GHCi;15
7.1.5;The Time Machine Store;16
7.1.6;Summary;17
7.2;Chapter 2: Declaring the Data Model;18
7.2.1;Working with Characters, Numbers, and Lists;18
7.2.1.1;Characters;18
7.2.1.2;Numbers;20
7.2.1.3;Strings;21
7.2.1.4;Lists;21
7.2.1.5;List Operations;22
7.2.2;Creating a New Project;25
7.2.2.1;Creating a Project from the Command Line;25
7.2.2.2;Creating a Project from EclipseFP;25
7.2.2.3;Understanding Modules;28
7.2.3;Defining Simple Functions;29
7.2.3.1;Creating a Simple Function;29
7.2.3.2;Specifying the Function’s Type;30
7.2.3.3;Developing a Robust Example;30
7.2.3.4;Returning More Than One Value;32
7.2.4;Working with Data Types;33
7.2.5;Pattern Matching;36
7.2.5.1;Simple Patterns;36
7.2.5.2;Lists and Tuples;40
7.2.5.3;Guards;41
7.2.5.4;View Patterns;43
7.2.6;Records;44
7.2.6.1;Creation and Use;44
7.2.6.2;The Default Values Idiom;46
7.2.7;Summary;48
7.3;Chapter 3: Reusing Code Through Lists;49
7.3.1;Parametric Polymorphism;49
7.3.2;Functions As Parameters;52
7.3.2.1;Higher-Order Functions;52
7.3.2.2;Anonymous Functions;54
7.3.2.3;Partial Application of a Function;56
7.3.3;More on Modules;59
7.3.3.1;Module Imports;59
7.3.3.2;Smart Constructors and Views;61
7.3.4;Diving into Lists;63
7.3.4.1;Folds;63
7.3.4.2;Lists and Predicates;66
7.3.4.3;Lists Containing Tuples;71
7.3.5;List Comprehensions;72
7.3.6;Haskell Origami;75
7.3.7;Summary;78
7.4;Chapter 4: Using Containers and Type Classes;79
7.4.1;Using Packages;79
7.4.1.1;Managing Packages with Cabal and EclipseFP;79
7.4.1.2;Sandboxed Environments;84
7.4.2;Containers: Maps, Sets, Trees, Graphs;86
7.4.2.1;Maps;86
7.4.2.2;Sets;89
7.4.2.3;Trees;91
7.4.2.4;Graphs;92
7.4.2.5;Obtaining Help;94
7.4.3;Ad Hoc Polymorphism: Type Classes;96
7.4.3.1;Declaring Classes and Instances;96
7.4.3.2;Built-in Type Classes;99
7.4.4;Binary Tress for the Minimum Price;103
7.4.4.1;Step 1: Simple Binary Trees;103
7.4.4.2;Step 2: Polymorphic Binary Trees;104
7.4.4.3;Step 3: Binary Trees with Monoidal Cache;106
7.4.5;Container-Related Type Classes;108
7.4.5.1;Functors;108
7.4.5.2;Foldables;109
7.4.6;Summary;111
7.5;Chapter 5: Laziness and Infinite Structures;112
7.5.1;An Infinite Number of Time Machines;112
7.5.2;Lazy Evaluation Model;116
7.5.2.1;Understanding Evaluation in Haskell;116
7.5.2.2;Problems with Laziness;120
7.5.2.3;Pattern Matching and Laziness;122
7.5.3;Profiling with GHC;123
7.5.4;Strictness Annotations;128
7.5.5;Summary;130
8;Part 2: Data Mining;131
8.1;Chapter 6: Knowing Your Clients Using Monads;132
8.1.1;Data Mining;132
8.1.1.1;Implementing K-means;133
8.1.1.2;Lenses;137
8.1.2;Discovering Monads;143
8.1.2.1;Watching Out for Incomplete Data;143
8.1.2.2;Combinators for State;145
8.1.2.3;Dissecting the Combinators;147
8.1.2.4;do Notation;149
8.1.2.5;Monad Laws;152
8.1.3;Different Sorts of State;153
8.1.3.1;State and Lenses;153
8.1.3.2;Reader, Writer, and RWS;154
8.1.3.3;Mutable References with ST;158
8.1.4;Summary;159
8.2;Chapter 7: More Monads: Now for Recommendations;160
8.2.1;Returning More Than One Value;160
8.2.1.1;The List Monad;161
8.2.1.2;A New View Over Monads;162
8.2.2;Failures and Alternatives;163
8.2.3;Association Rules Learning;166
8.2.3.1;Flattening Values into Transactions;166
8.2.3.2;The Apriori Algorithm;168
8.2.4;Search Problems;171
8.2.4.1;Paths in a Graph;171
8.2.4.2;The Logic Monad;172
8.2.5;Monads and Lists Redux;174
8.2.5.1;Combining Values Under a Monad;174
8.2.5.2;Monad Comprehensions;177
8.2.6;Combining Monads;179
8.2.6.1;Monad Transformers;179
8.2.6.2;Monad Classes;182
8.2.7;Summary;184
8.3;Chapter 8: Working in Several Cores;185
8.3.1;Parallelism, Concurrency, and Distribution;185
8.3.2;The Par Monad;186
8.3.2.1;Futures;186
8.3.2.2;Dataflow Parallelism with IVars;188
8.3.2.3;Parallelizing the Apriori Algorithm;190
8.3.3;Software Transactional Memory;192
8.3.3.1;Concurrent Use of Resources;192
8.3.3.2;Atomic Transactions;194
8.3.3.3;Rolling Back Transactions;195
8.3.3.4;Producer-Consumer Queues;197
8.3.4;Cloud Haskell;198
8.3.4.1;Looking for Galaxies;198
8.3.4.2;Looking for Typed Galaxies;202
8.3.4.3;Extra Features;203
8.3.5;Summary;203
9;Part 3: Resource Handling;204
9.1;Chapter 9: Dealing with Files: IO and Conduit;205
9.1.1;Basic Input and Output;205
9.1.2;Randomness;209
9.1.3;Working with Files;211
9.1.3.1;Reading and Writing;211
9.1.3.2;Handling Files;213
9.1.4;Error Handling;214
9.1.4.1;Pure Errors;214
9.1.4.2;Catching Exceptions;217
9.1.4.3;Throwing Exceptions;220
9.1.5;Streaming Data with Conduit;221
9.1.5.1;Problems with Lazy Input/Output;221
9.1.5.2;Introducing Conduits;222
9.1.5.3;Accessing Files via Conduit;226
9.1.6;Looking Further Than Text Files;227
9.1.6.1;Basic Networking;227
9.1.6.2;Binary Serialization;229
9.1.7;Summary;230
9.2;Chapter 10: Building and Parsing Text;231
9.2.1;The Five Textual Data Types;231
9.2.2;Building as Fast as the Wind;235
9.2.3;Parsing with attoparsec;237
9.2.4;Introducing New Type Classes;242
9.2.4.1;Applicative;242
9.2.4.2;Functors, Applicatives, and Monads;244
9.2.4.3;Alternative;246
9.2.4.4;Traversable;247
9.2.5;Don’t Overengineer: Just Use JSON;249
9.2.6;Summary;254
9.3;Chapter 11: Safe Database Access;255
9.3.1;Database Access Landscape;255
9.3.1.1;Abstracting Over Several DBMSs;256
9.3.1.2;Introducing Persistent and Esqueleto;256
9.3.2;Connection;257
9.3.3;Schemas and Migrations;258
9.3.3.1;Describing the Entities;259
9.3.3.2;Creating the Database;262
9.3.4;Queries;265
9.3.4.1;Queries by Identifier or Uniqueness;265
9.3.4.2;Selecting Several Entities;266
9.3.4.3;SQL Queries with Esqueleto;267
9.3.5;Insertions, Updates, and Deletions;270
9.3.6;Summary;272
9.4;Chapter 12: Web Applications;273
9.4.1;Haskell Web Ecosystem;273
9.4.1.1;Web Frameworks;273
9.4.1.2;Compilation to JavaScript;275
9.4.2;RESTful Structure;275
9.4.3;Back End with Scotty;276
9.4.3.1;Simple Skeleton;276
9.4.3.2;Showing Products from the Database;277
9.4.3.3;Inserting New Products Using Forms;281
9.4.4;Front End with Fay;285
9.4.4.1;Foreign Function Interface;286
9.4.4.2;Fay and jQuery;287
9.4.5;Summary;290
10;Part 4: Domain Specific Languages;291
10.1;Chapter 13: Strong Types for Describing Offers;292
10.1.1;Domain-Specific Languages;292
10.1.1.1;Embedding Your Language in Haskell;293
10.1.1.2;The Offers Language;294
10.1.2;Adding Safety to the Expression Language;296
10.1.3;Dependent Typing;299
10.1.3.1;Introducing Idris;300
10.1.3.2;Enforcing the Presents Rule in Idris;303
10.1.4;Type-Level Programming in Haskell;304
10.1.4.1;Two Styles of Programming;305
10.1.4.2;Representing Natural Numbers;305
10.1.5;Functional Dependencies;307
10.1.5.1;Categories of Products with FDs;307
10.1.5.2;Enforcing the Presents Rule with FDs;309
10.1.6;Type Families;312
10.1.6.1;Enforcing the Presents Rule with TFs;312
10.1.6.2;Categories of Products with TFs;314
10.1.7;Data Type Promotion and Singletons;318
10.1.7.1;A Further Refinement to the Presents Rule;318
10.1.7.2;Enforcing the Duration Rule;321
10.1.8;Summary;325
10.2;Chapter 14: Interpreting Offers with Attributes;327
10.2.1;Interpretations and Attribute Grammars;327
10.2.1.1;A Simple Interpretation;327
10.2.1.2;Introducing Attribute Grammars;328
10.2.2;Your First Attribute Grammar;329
10.2.2.1;Synthesizing the Result;329
10.2.2.2;Executing the Attribute Grammar;330
10.2.3;Integrating UUAGC in Your Package;331
10.2.3.1;Installing UUAGC;331
10.2.3.2;UUAGC and Cabal;332
10.2.4;Expressions Interpretation;334
10.2.4.1;Using an Attribute Grammar;334
10.2.4.2;Precomputing Some Values;336
10.2.4.3;A Different (Monadic) View;337
10.2.5;Offer Interpretations;339
10.2.5.1;Checking the Presents Rule;339
10.2.5.2;Showing an HTML Description;340
10.2.6;Origami Programming Over Any Data Type;344
10.2.7;Summary;346
11;Part 5: Engineering the Store;347
11.1;Chapter 15: Documenting, Testing, and Verifying;348
11.1.1;Documenting Binary Trees with Haddock;348
11.1.2;Unit Testing with HUnit;352
11.1.2.1;Declaring Tests in Cabal;352
11.1.2.2;Writing Unit Tests;354
11.1.3;Randomized Testing with QuickCheck;357
11.1.3.1;Testing List Properties;357
11.1.3.2;Testing Binary Tree Properties;358
11.1.4;Formal Verification with Idris;360
11.1.5;Summary;364
11.2;Chapter 16: Architecting Your Application;365
11.2.1;Design Patterns and Functional Programming;365
11.2.2;Medium-Level Guidelines;366
11.2.2.1;Use Higher-Order Combinators;366
11.2.2.2;Refactor;367
11.2.2.3;Use Type Classes Wisely;367
11.2.2.4;Enforce Invariants via the Type System;367
11.2.2.5;Stay (as) Pure and Polymorphic (as Possible);367
11.2.3;Tools;368
11.2.3.1;Project and Dependency Management;368
11.2.3.2;Code Style;368
11.2.3.3;Documentation;369
11.2.3.4;Test and Verification;369
11.2.3.5;Benchmarking;369
11.2.3.6;Profiling;369
11.2.3.7;Coverage;369
11.2.3.8;Remote Monitoring;370
11.2.4;Projects;370
11.2.4.1;Data Mining Library;370
11.2.4.2;Store Network Client;371
11.2.4.3;Administration Interface and Tetris;376
11.2.4.4;Roll Your Own Monad;377
11.2.5;Summary;379
11.3;Appendix A: Looking Further;380
11.3.1;Haskell Resources;380
11.3.1.1;Other Functional Languages;381
11.4;Appendix B: Time Traveling with Haskell;382
12;Index;384