Log In
Or create an account ->
Imperial Library
Home
About
News
Upload
Forum
Help
Login/SignUp
Index
F# 4.0 Design Patterns
Table of Contents
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
Note
Tip
Reader feedback
Customer support
Downloading the example code
Errata
Piracy
Questions
Chapter 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
Chapter 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
Chapter 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
Note
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
Tip
Recursive function basics
Operators as functions
Note
Function composition
Combinators
The id combinator
Forward pipe |>
Backward pipe <|
Forward composition >>
Backward composition
Summary
Chapter 4. Basic Pattern Matching
An explicit form of pattern matching with match construction
Matching literals
Wildcard matching
Arranging matching rules
Named patterns
Tip
The as pattern
Grouping patterns
Guards
The alternative syntax for anonymous function performing matching
Summary
Chapter 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
Note
Record decomposition with pattern matching
Record augmentation
Sum algebraic data types
Discriminated unions
Discriminated union composition
Discriminated union equality and comparison
Discriminated union decomposition with pattern matching
Discriminated union augmentation
Summary
Chapter 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
Library functions generating sequences
Sequence and the code performance
Sequence caching
The fusion of sequence transformations
Summary
Chapter 7. Advanced Techniques: Functions Revisited
A deep dive into recursion
Tail recursion
Mutual recursion
Folding
Note
Memoization
Lazy evaluation
Continuation passing style
Active patterns
Type transformations with active patterns
Data partitioning with active patterns
Data categorization with active patterns
Summary
Chapter 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 an unknown size
Tip
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
Tip
Tip
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
Chapter 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>
Tip
External data querying via IQuerable<'T>
Note
Composable queries
Note
Data parsing
The use case - LaserShip invoicing
Approaching the parsing task
LaserShip parser implementation
Summary
Chapter 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
Chapter 11. F# Expert Techniques
A note on custom computation expressions
Note
Exploring type providers
The feature review
Tip
The demo problem
The demo solution
Note
Exploring concurrent computations
The feature review
The demo problem
The demo solution
Tip
Exploring reactive computations
The feature review
Note
The demo problem
The demo solution
Exploring quotations and metaprogramming
The feature review
The demo problem
The demo solution
Summary
Chapter 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
Chapter 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
← Prev
Back
Next →
← Prev
Back
Next →