万本电子书0元读

万本电子书0元读

顶部广告

F# 4.0 Design Patterns电子书

售       价:¥

8人正在读 | 0人评论 9.8

作       者:Gene Belitski

出  版  社:Packt Publishing

出版时间:2016-11-01

字       数:363.3万

所属分类: 进口书 > 外文原版书 > 电脑/网络

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

为你推荐

  • 读书简介
  • 目录
  • 累计评论(0条)
  • 读书简介
  • 目录
  • 累计评论(0条)
Learn how to apply functional F# design patterns to a huge range of programming challenges, and discover a smart route to building better applications About This Book This book provides a path if you are coming from imperative and object-oriented paradigms It will take you to an intermediate level of functional programming in very practical manner to write enterprise-quality idiomatic F# code Tackle complex computing problems with simple code by fully embracing the functional-first F# paradigm Packed full of practical coding examples to help you master F# programming and author optimal code Who This Book Is For This book is for .NET developers, web programmers, C# developers, and F# developers. So, if you have basic experience in F# programming and developing performance-critical applications, then this book is for you. What You Will Learn Acquire the practical knowledge to use the main functional design patterns Realign some imperative and object-oriented principles under the functional approach Develop your confidence in building and combining first-order and higher-order functions Learn to use core language pattern matching effectively Make use of native F# algebraic data types in place of custom-built classes Recognize and measure the difference in resource consumption between sequences and materialized data collections Navigate and use F# Core libraries with ease by seeing patterns behind specific library functions Master writing generic polymorphic code In Detail Following design patterns is a well-known approach to writing better programs that captures and reuses high-level abstractions that are common in many applications. This book will encourage you to develop an idiomatic F# coding skillset by fully embracing the functional-first F# paradigm. It will also help you harness this powerful instrument to write succinct, bug-free, and cross-platform code. F# 4.0 Design Patterns will start off by helping you develop a functional way of thinking. We will show you how beneficial the functional-first paradigm is and how to use it to get the optimum results. The book will help you acquire the practical knowledge of the main functional design patterns, the relationship of which with the traditional Gang of Four set is not straightforward. We will take you through pattern matching, immutable data types, and sequences in F#. We will also uncover advanced functional patterns, look at polymorphic functions, typical data crunching techniques, adjusting code through augmentation, and generalization. Lastly, we will take a look at the advanced techniques to equip you with everything you need to write flawless code. Style and approach This book will teach you how to write F# code in an idiomatic functional-first manner, thereby improving the productivity of F# programmers. This book is ideal for an F# programmer who wants using F# in functional-first way.
目录展开

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

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

发表评论

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

买过这本书的人还买过

读了这本书的人还在读

回顶部