万本电子书0元读

万本电子书0元读

顶部广告

Haskell Design Patterns电子书

售       价:¥

6人正在读 | 0人评论 9.8

作       者:Ryan Lemmer

出  版  社:Packt Publishing

出版时间:2015-11-01

字       数:140.0万

所属分类: 进口书 > 外文原版书 > 其他

温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Take your Haskell and functional programming skills to the next level by exploring new idioms and design patternsAbout This BookExplore Haskell on a higher level through idioms and patternsGet an in-depth look into the three strongholds of Haskell: higher-order functions, the Type system, and Lazy evaluationExpand your understanding of Haskell and functional programming, one line of executable code at a timeWho This Book Is ForIf you’re a Haskell programmer with a firm grasp of the basics and ready to move more deeply into modern idiomatic Haskell programming, then this book is for you.What You Will LearnUnderstand the relationship between the “Gang of Four” OOP Design Patterns and HaskellTry out three ways of Streaming I/O: imperative, Lazy, and Iteratee basedExplore the pervasive pattern of Composition: from function composition through to high-level composition with LensesSynthesize Functor, Applicative, Arrow and Monad in a single conceptual frameworkFollow the grand arc of Fold and Map on lists all the way to their culmination in Lenses and Generic ProgrammingGet a taste of Type-level programming in Haskell and how this relates to dependently-typed programmingRetrace the evolution, one key language extension at a time, of the Haskell Type and Kind systemsPlace the elements of modern Haskell in a historical frameworkIn DetailDesign patterns and idioms can widen our perspective by showing us where to look, what to look at, and ultimately how to see what we are looking at. At their best, patterns are a shorthand method of communicating better ways to code (writing less, more maintainable, and more efficient code).This book starts with Haskell 98 and through the lens of patterns and idioms investigates the key advances and programming styles that together make "modern Haskell". Your journey begins with the three pillars of Haskell. Then you'll experience the problem with Lazy I/O, together with a solution. You'll also trace the hierarchy formed by Functor, Applicative, Arrow, and Monad. Next you'll explore how Fold and Map are generalized by Foldable and Traversable, which in turn is unified in a broader context by functional Lenses. You'll delve more deeply into the Type system, which will prepare you for an overview of Generic programming. In conclusion you go to the edge of Haskell by investigating the Kind system and how this relates to Dependently-typed programming.Style and approachUsing short pieces of executable code, this guide gradually explores the broad pattern landscape of modern Haskell. Ideas are presented in their historical context and arrived at through intuitive derivations, always with a focus on the problems they solve.
目录展开

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

累计评论(0条) 0个书友正在讨论这本书 发表评论

发表评论

发表评论,分享你的想法吧!

买过这本书的人还买过

读了这本书的人还在读

回顶部