售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
Haskell Design Patterns
Table of Contents
Haskell Design Patterns
Credits
About the Author
About the Reviewer
www.PacktPub.com
Support files, eBooks, discount offers, and more
Why subscribe?
Free access for Packt account holders
Preface
What this book covers
What you need for this book
Who this book is for
Conventions
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
1. Functional Patterns – the Building Blocks
Higher-order functions
Functions as first-class citizens
Composing functions
Currying functions
Currying and composability
Decoupling with currying
Recursion
Non-tail recursion
Tail recursion
Folding abstracts recursion
Types, pattern matching, and polymorphism
Algebraic types and pattern matching
Recursive types
Polymorphism
Parametric polymorphism
Ad-hoc polymorphism
Alternation-based ad-hoc polymorphism
Class-based ad-hoc polymorphism
Alternation-based versus class-based
Polymorphic dispatch and the visitor pattern
Unifying parametric and ad-hoc polymorphism
Functions, types, and patterns
The strategy pattern
The template pattern
The iterator pattern
Decoupling behavior and modularizing code
Lazy evaluation
Streams
Modeling change with streams
Lazy evil
Monads
Composing monads and structuring programs
Summary
2. Patterns for I/O
I/O as a first class citizen
I/O as a functor, applicative, and monad
Imperative I/O
Lazy I/O
The problems with lazy I/O
Resource management with bracket
Iteratee I/O
Iteratee
Enumerator
Generalized iteratees, enumerators, and enumeratees
The iteratee I/O libraries
Comparing the three styles of I/O
Summary
3. Patterns of Composition
Functor
Applicative functor
Monad
Monad as functor
Monad as applicative
Sequencing actions with monad and applicative
Monads and the bind chain
Composing with monads
Monad transformers
IO in monad stacks
Sequence of stack composition
Arrows
Implementing an arrow
Arrow operators
Kleisli arrows and monad arrows
Why arrows?
Summary
4. Patterns of Folding and Traversing
Folding over lists
Folding with monadic functions
Folding with monoids
Foldable
Mapping over lists
Traversable
A Traversable Tree
The traversal and the Iterator pattern
Modernizing Haskell 98
Lenses
Deriving Lens
Writing a Lens
Composable getters and setters
Lens Traversal
Lens.Fold
The Lens library
Summary
5. Patterns of Type Abstraction
Abstracting function types: RankNTypes
Abstracting datatypes
Universal quantification
Existential quantification and abstract datatypes
Phantom types
Generalized algebraic datatypes
Typecase pattern
Dynamic types
Heterogeneous lists
Using existentials
Using GADTs
Abstracting type-classes
Multiparameter type-classes
Functional dependencies
Summary
6. Patterns of Generic Programming
Patterns of generic programming
Patterns 1 and 2 – functions
Pattern 3 – polymorphic types and functions
Pattern 4 – type-class polymorphism
Pattern 5 – meta-programming
The Derivable type-classes
Generalized newtype deriving
Pattern 6 – type laws
Pattern 7 – datatype generic programming
The sum of products style
The sum of products type representation
Translating between the type and representation
Writing a datatype-generic function
Adding a new datatype
GHC.Generics – a generic deriving mechanism
Origami programming
Tying the recursive knot
The generic map
The generic fold
main = print $ gfold addL aListF
Generic unfold and fold
Origami design patterns
Scrap your boilerplate
The type-safe cast with typeable
Type-safe function application
The shallow traversal and the data type-class
Typeable and data
Scrap your boilerplate
Summary
7. Patterns of Kind Abstraction
Higher-order kinds
Higher-kinded polymorphism
Associated type synonyms
Using functional dependencies
Associated type synonyms
Associated types versus functional dependencies
Type (synonym) families
Data families
Kind polymorphism
The PolyKinds language extension
Type promotion
Promoting types to kinds
Type-level programming
Promoting term-level programs to type-level
Closed type families
The history of type-level programming in Haskell
Type-level and generic programming
Dependently-typed programming
Haskell and dependently-typed programming
Summary
Epilogue
Index
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜