售 价:¥
温馨提示:数字商品不支持退换货,不提供源文件,不支持导出打印
为你推荐
F# 4.0 Design Patterns
F# 4.0 Design Patterns
Credits
About the Author
Acknowledgements
About the Reviewer
www.PacktPub.com
Why subscribe?
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. Begin Thinking Functionally
Relationship between F# and programming paradigms
A sample problem to solve
An imperative monolithic solution
An object-oriented solution
A functional solution
Immutability of participating data entities
Thinking in verbs rather than nouns
"What" prevailing over "how"
Generalization over specialization
Minimizing moving parts over hiding them
Reduction to known parts over producing custom parts
Lazy over eager data collections
Summary
2. Dissecting F# Origins and Design
The evolvement of F#
Predecessors
F# Version 1
F# Version 1.1
F# Version 2
F# Version 3
F# Version 4
Predecessor inherited language features
F# functions are first-class entities
Functions are free of side effects
Functions can be curried and partially evaluated
Functions may be anonymous
Functions may be recursive
Functions may raise exceptions
Functions may reference external values
F# is a statically typed language
F# type inference provides type generalization
F# supports parametric polymorphism
F# inherits the variety of aggregate data structures from ML
F# supports pattern matching
F# supports data references
Functions are non-recursive by default
Modules
.NET-imposed language features
F# adheres to .NET Common Language Infrastructure
F# has nominal type system
F# fully embraces .NET object orientation
F# requires calling the method of an explicit interface
Object expressions
Reflection
Extending classes and modules
Enumerations
Structures
Events
Nullable types
Interoperation with the managed code
Interoperation with unmanaged code
Intrinsic F# language features
Indentation-aware syntax
Units of measure
Overloaded operators
Inline Functions
Type constraints and statically resolved type parameters
Active Patterns
Computation Expressions
Query Expressions
Asynchronous workflows
Meta-programming
Type providers
Summary
3. Basic Functions
The notion of function in F#
The function definition
The function type signature
Pure functions
Function parameters and arguments
The tuples preview
Special type unit
Currying and partial function application
The number and the type of function parameters and return values
Higher-order functions
Anonymous functions
Functions as arguments
Functions as return values
Functions as data type constituents
Functions are interfaces
Closures
Mutable values
Reference cells
Type inference
Recursive function basics
Operators as functions
Function composition
Combinators
The id combinator
Forward pipe |>
Backward pipe <|
Forward composition >>
Backward composition
Summary
4. Basic Pattern Matching
An explicit form of pattern matching with match construction
Matching literals
Wildcard matching
Arranging matching rules
Named patterns
The as pattern
Grouping patterns
Guards
The alternative syntax for anonymous function performing matching
Summary
5. Algebraic Data Types
Combining data with algebraic data types
Product algebraic data types
Tuples
Tuple composition
Tuple equality and comparison
Tuple decomposition with pattern matching
Tuple augmentation
Records
Record composition
Record equality and comparison
Record decomposition with pattern matching
Record augmentation
Sum algebraic data types
Discriminated unions
Discriminated union composition
The empty constructor case
The single constructor case
Discriminated union equality and comparison
Discriminated union decomposition with pattern matching
Discriminated union augmentation
Summary
6. Sequences - The Core of Data Processing Patterns
Basic sequence transformations
The aggregation pattern
The generation pattern
The wrapping and type conversion pattern
The application pattern
The recombination pattern
The filtering pattern
The mapping pattern
The sequence: Duality of data and calculation
Sequence as a lazy data collection
Sequence as a calculation
Sequence as an enumerator interface wrapper
Step 1 - The custom enumerator implementation
Step 2 - The custom enumerator factory
Step 3 - The custom sequence factory
Sequence of an indefinite length as a design pattern
Generating the F# sequences
Sequence comprehensions
Ranges
Maps
Arbitrary sequence expressions
Library functions generating sequences
Seq.init
Seq.initInfinite
Seq.unfold
Sequence and the code performance
Sequence caching
The fusion of sequence transformations
Summary
7. Advanced Techniques: Functions Revisited
A deep dive into recursion
Tail recursion
Mutual recursion
Folding
Memoization
Lazy evaluation
Continuation passing style
Active patterns
Type transformations with active patterns
Data partitioning with active patterns
Data categorization with active patterns
Summary
8. Data Crunching – Data Transformation Patterns
Core data transformation libraries in F# 4.0
Data transformation patterns
The generation pattern
Generating an empty collection
Generating a single element collection
Generating a collection of a known size
Generating a collection of a known size - all elements of the same value
Generating a collection of a known size - elements may have different values
Generating a collection of an unknown size
Generating a collection of an infinite size
The aggregation pattern
Generic aggregation
Direct aggregation
Projected aggregation
Counting aggregation
The wrapping and type conversion pattern
The collection wrapping pattern
The type conversion pattern
The selection pattern
The position-based selection pattern
Single element selection
The element group selection
The searching pattern
The partitioning pattern
The reordering pattern
The testing pattern
The iterating pattern
The mapping pattern
The folding pattern
The merge/split pattern
Summary
9. More Data Crunching
Data querying
F# and LINQ before query expressions
Introducing F# query expressions
Query operators
The role of a LINQ provider
External data querying via IEnumerable<'T>
External data querying via IQuerable<'T>
Composable queries
Data parsing
The use case - LaserShip invoicing
Approaching the parsing task
LaserShip parser implementation
Summary
10. Type Augmentation and Generic Computations
Code generalization
Statically resolved type parameters
Function inlining
Static constraints
Explicit or inferred constraining?
Inlining scope
Inline optimizations
Writing generic code
Type augmentation
Augment by removing
Augment by adding
Summary
11. F# Expert Techniques
A note on custom computation expressions
Exploring type providers
The feature review
The demo problem
The demo solution
Exploring concurrent computations
The feature review
The demo problem
The demo solution
Exploring reactive computations
The feature review
The demo problem
The demo solution
Exploring quotations and metaprogramming
The feature review
The demo problem
The demo solution
Summary
12. F# and OOP Principles/Design Patterns
Morphing SOLID principles
Single Responsibility Principle
Open/Closed Principle
Liskov Substitution Principle
Interface Segregation Principle
Dependency Inversion Principle
Diminishing patterns
The Command design pattern
The Template design pattern
The Strategy pattern
Summary
13. Troubleshooting Functional Code
Why idiomatic F# admits less defects
Reduced bug rate
Prevalence of F# compile-time errors over run-time bugs
Using REPL and the explorative programming style
Addressing some compile-time problems
The if-then return value
Value restriction
Imperfect pattern matching
Addressing run-time problems
Summary
买过这本书的人还买过
读了这本书的人还在读
同类图书排行榜