Effective Haskell: Solving Real-World Problems with Strongly Typed Functional Programming [1 ed.] 1680509349, 9781680509342

Put the power of Haskell to work in your programs, learning from an engineer who uses Haskell daily to get practical wor

232 63 3MB

English Pages 668 [663] Year 2023

Report DMCA / Copyright

DOWNLOAD FILE

Effective Haskell: Solving Real-World Problems with Strongly Typed Functional Programming [1 ed.]
 1680509349, 9781680509342

  • Commentary
  • Publisher's PDF | Book version: P1.0—July 2023 | Published: August 2023

Table of contents :
Cover
Table of Contents
Acknowledgments
Foreword
Introduction
Why Choose Haskell?
Why This Book
How to Read This Book
1. Getting Started with Haskell
Exploring Haskell Interactively
Writing Your First Haskell Program
Formatting Haskell Code
Creating New Variables
Writing Functions
Precedence, Operators, and Fixity
Creating Local Variables Using Let Bindings
Running Code Conditionally Using Branches
Looping
Summary
Exercises
2. Working with Lists
Writing Code Using Lists
Destructuring Values with Pattern Matching
Understanding How Programs Are Evaluated
Hands-On with Infinite Fibonacci Numbers
Summary
Exercises
3. Getting Started with Types
Working with Basic Haskell Types
Annotating Values with Type Information
Looking Up Type Information
Writing Type Annotations for Functions
Reading Type Errors
Working with Polymorphic Functions
Exploring the Type Space of an Application with Undefined
Getting Help from Type Holes
Looking at the Type of main
Summary
Exercises
4. Creating New Types
Creating Data Types and Records
Creating Sum Types
Creating Inductively Defined Data Structures
Building a Calculator
Functions as Values
Creating Type Aliases
Summary
Exercises
5. Creating And Structuring Haskell Projects
Creating Haskell Projects
Using Code from Other Modules
Creating Your Own Modules
Choosing What to Export
Documenting Modules
Summary
Exercises
6. Type Classes
Using Ad Hoc Polymorphism with Type classes
Specifying Type Class Instances with Type Applications
Wrapping Types with Newtype
Understanding Higher Kinded Types and Polymorphism
Deriving Instances
Deriving More Things
Summary
Exercises
7. Understanding IO
Talking About IO
Performing IO in a Pure, Lazy Language
Ordering and Combining IO Actions
Independently Sequencing IO Actions
Mapping IO Values with fmap
Running IO in Real Applications
Summary
Exercises
8. Working with the Local System
Building Applications with IO
Procedural Shell, Functional Core
Creating a Pager
Viewing the Contents of an ASCII or UTF8 Encoded Text File
Viewing Text One Page at a Time
Adding a Status Line with Metadata
Showing the Status Bar and Refactoring runHCat
Summary
Exercises
9. Introducing Monads
Mapping Functors
Applying Applicatives
Working with the Monad Type Class
Understanding the Laws of the Land
Using the Functor Laws
Using the Monad Laws
Using the Applicative Laws
Summary
Exercises
10. Mutable Data in the Real World
Using Mutable References in a Pure Language
Working with IORefs
Building a Basic Metrics System with IORefs
Dealing with Laziness and IO
Summary
Exercises
11. Serializing Heterogenous Data
Heterogenous Data in Haskell
A First Pass at a File Archiver
Serializing with Type Classes
Building a List of FileData Values
Summary
Exercises
12. Deserializing Heterogenous Data
Extracting Heterogenous Values from the Archive
Deserialization as Parsing
Creating a Parsing Function
Building a Monadic Parser
Parsing a List of Values
Adding a Monad Instance
Adding a MonadFail Instance
Summary
Exercises
13. Building Applications with Many Effects
Revisiting the Parsing Problem
Handling Errors in Other Computations
State, Transformed
Stacking Transformers Effectively
Building a File Archiver
Summary
Exercises
14. Building Efficient Programs
Building a Naive Spellchecker
Memoizing editDistance
Internal Mutability with ST
Optimizing Memory Layout with Vectors
The Fastest Edit Distance
Summary
Exercises
15. Programming with Types
What Is Type Level Programming?
Types and Kinds
Functions from Types to Types
GADTs: Functions from Terms to Types
Type Classes: Functions from Types to Terms
Summary
Exercises
Index
– SYMBOLS –
– A –
– B –
– C –
– D –
– E –
– F –
– G –
– H –
– I –
– J –
– K –
– L –
– M –
– N –
– O –
– P –
– Q –
– R –
– S –
– T –
– U –
– V –
– W –
– X –
– Z –

Polecaj historie