Expert F#

Free Download

Authors:

Edition: 1

Series: Expert's voice in .NET

ISBN: 1590598504, 9781590598504

Size: 13 MB (13488353 bytes)

Pages: 639/639

File format:

Language:

Publishing Year:

Category: Tags: , ,

Antonio Cisternino, Adam Granicz, Don Syme1590598504, 9781590598504

Expert F# is about practical programming in a beautiful language that puts the power and elegance of functional programming into the hands of .NET developers. In combination with .NET, F# achieves unrivaled levels of programmer productivity and program clarity. This books serves as
The authoritative guide to F# by the designer of F# A comprehensive reference of F# concepts, syntax, and features A treasury of expert F# techniques for practical, real–world programming
While inspired by OCaml, F# isn’t just another functional programming language. Drawing on many of the strengths of both OCaml and .NET, it’s a general–purpose language ideal for real–world development. F# integrates functional, imperative, and object–oriented programming styles so you can flexibly and elegantly solve programming problems, and brings .NET development alive with interactive execution. Whatever your background, you’ll find that F# is easy to learn, fun to use, and extraordinarily powerful. F# will help change the way you think about and go about programming.

Written by F#’s designer and two active contributors, Expert F# is the authoritative, comprehensive, and in–depth guide to the language and its use. Designed to help others become experts, the book gives a thorough introduction to the F# language from quick essentials to in–depth advanced topics such as active pattern matching, aggregate data types and operators, sequence expressions, lazy values, mutable data and side–effects, generics, type augmentations, functional decomposition and code organization.

The second half of the book is devoted to examining the practical application of F#, providing elegant solutions to common programming tasks including UI implementation, data access, web and distributed programming, symbolic and numerical computations, concurrent programming, testing, profiling, and interoperability with other languages. The latest hot developments in F# and .NET are also addressed, including Active Patterns, implicit class construction, integration with LINQ over relational data, meta programming and useful tips for working with Visual Studio and F# command–line tools.

The worlds foremost experts in F# show you how to program in F# the way they do!
What you’ll learn How to use F# for functional, imperative, and object–oriented programming How to code elegant F# solutions with expert technique and style How to develop Windows, web, graphics, and database applications in F# How to do numerical, concurrent, lexical, and symbolic processing in F# How to interoperate with C and COM Who this book is for
This book is for anyone interested in state–of–the art .NET programming. Professional programmers will find it engrossing. F# provides invaluable insight into the future of both C# and VB, which are now adopting some (but far from all) of the functional features of F#. Once they learn F#, few feel like returning to either C# or VB. The academic community will find F# the answer to a decades–long prayer: a language suitable for teaching computer science that also excites and empowers students because it can be used not just in the classroom, but also in the real world.


Table of contents :
Expert F#……Page 1
Contents at a Glance……Page 7
Contents……Page 9
Foreword……Page 23
About the Authors……Page 25
About the Technical Reviewer……Page 27
Acknowledgments……Page 29
The Genesis of F#……Page 31
About This Book……Page 32
Who This Book Is For……Page 35
Creating Your First F# Program……Page 37
Turning On the Lightweight Syntax Option……Page 39
Understanding Scope and Using fietf……Page 40
Understanding Types……Page 43
Calling Functions……Page 44
Using Data Structures……Page 45
Using Properties and the Dot-Notation……Page 46
Using Tuples……Page 47
Using Imperative Code……Page 49
Using .NET Libraries from F#……Page 50
Using open to Access Namespaces and Modules……Page 51
Using new and Setting Properties……Page 52
Fetching a Web Page……Page 53
Summary……Page 55
Basic Literals……Page 57
Arithmetic Operators……Page 58
Bitwise Operations……Page 59
Arithmetic Conversions……Page 60
Introducing Simple Strings……Page 61
Working with String Literals and Primitives……Page 62
Building Strings……Page 63
Using F# Lists……Page 64
Using F# Option Values……Page 67
Working with Conditionals: && and ||……Page 69
Defining Recursive Functions……Page 70
Introducing Function Values……Page 72
Using Anonymous Function Values……Page 73
Computing with Aggregate Operators……Page 74
Composing Functions with >>……Page 75
Building Functions with Partial Application……Page 76
Using Local Functions……Page 77
Using Functions As Abstract Values……Page 78
Abstracting Control with Functions……Page 79
Using .NET Methods As First-Class Functions……Page 80
Getting Started with Pattern Matching……Page 81
Matching on Structured Values……Page 83
Guarding Rules and Combining Patterns……Page 84
Using Range Expressions……Page 85
Transforming Sequences with Aggregate Operators……Page 86
Which Types Can Be Used As Sequences?……Page 87
Using Lazy Sequences from External Sources……Page 88
Using Sequence Expressions……Page 89
Enriching Sequence Expressions with Additional Clauses……Page 90
Enriching Sequence Expressions to Specify Lists and Arrays……Page 91
Defining Type Abbreviations……Page 92
Defining Records……Page 93
Cloning Records……Page 94
Defining Discriminated Unions……Page 95
Defining Multiple Types Simultaneously……Page 97
Summary……Page 98
Introducing Imperative Programming……Page 99
Simple for loops……Page 100
More Iteration Loops Over Sequences……Page 101
Using Mutable Records……Page 102
Mutable Reference Cells……Page 103
Avoiding Aliasing……Page 104
Hiding Mutable Data……Page 105
Using Mutable Locals……Page 106
Working with Arrays……Page 107
Generating and Slicing Arrays……Page 109
Using Resizeable Arrays……Page 110
Using Dictionaries……Page 111
Using Dictionary’s TryGetValue……Page 112
Using Dictionaries with Compound Keys……Page 113
Exceptions and Controlling Them……Page 114
Using try . . . finally……Page 116
Defining New Exception Types……Page 117
Very Simple I/O: Reading and Writing Files……Page 118
.NET I/O via Streams……Page 119
Using printf and Friends……Page 121
Cleaning Up with IDisposable, use, and using……Page 123
Working with null Values……Page 124
Some Advice: Functional Programming with Side Effects……Page 125
Separate Pure Computation from Side-Effecting Computations……Page 126
Separating Mutable Data Structures……Page 127
Avoid Combining Imperative Programming and Laziness……Page 128
Summary……Page 130
Understanding Generic Type Variables……Page 131
Writing Generic Functions……Page 132
Generic Comparison……Page 133
Generic Pretty-Printing……Page 135
Generic Boxing and Unboxing……Page 136
Generic Binary Serialization via the .NET Libraries……Page 137
Generic Algorithms Through Explicit Arguments……Page 138
Generic Algorithms Through Abstract Object Types……Page 140
Reference Types and Value Types……Page 142
Understanding Subtyping……Page 143
Casting Down Dynamically……Page 144
Performing Type Tests via Pattern Matching……Page 145
Using Flexible # Types……Page 146
Knowing When Upcasts Are Applied Automatically……Page 147
Using Type Annotations……Page 148
Understanding the Value Restriction……Page 149
Working Around the Value Restriction……Page 150
Technique 2: Ensure Generic Functions Have Explicit Arguments……Page 151
Technique 4: Add Explicit Type Arguments When Necessary……Page 152
Summary……Page 153
Getting Started with Objects and Members……Page 155
Using Constructed Classes……Page 158
Working with Indexer Properties……Page 161
Adding Overloaded Operators……Page 162
Using Named and Optional Arguments……Page 163
Using Optional Property Settings……Page 164
Adding Method Overloading……Page 165
Defining Object Types with Mutable State……Page 167
Getting Started with Object Interface Types……Page 169
Implementing Object Interface Types Using Object Expressions……Page 170
Using Common Object Interface Types from the .NET Libraries……Page 172
Understanding Hierarchies of Object Interface Types……Page 173
Combining Object Expressions and Function Parameters……Page 174
Using Partially Implemented Types via Delegation……Page 176
Using Partially Implemented Types via Implementation Inheritance……Page 177
Using Modules and Static Members……Page 178
Extending Existing Types and Modules……Page 180
Working with F# Objects and .NET Types……Page 181
Delegates……Page 182
Summary……Page 183
Encapsulating and Packaging Your Code……Page 185
Hiding Things with Local Definitions……Page 186
Hiding Things with Accessibility Annotations……Page 188
Using Namespaces and Modules……Page 191
Putting Your Code in a Namespace……Page 192
Using Files As Modules……Page 193
Using Explicit Signature Types and Signature Files……Page 194
Compiling EXEs……Page 196
Compiling DLLs……Page 197
Mixing Scripting and Compiled Code……Page 198
Choosing Optimization Settings……Page 199
Generating Documentation……Page 200
Building Shared Libraries and the Using Global Assembly Cache……Page 201
Using Static Linking……Page 202
Packaging Different Kinds of Code……Page 203
Using Data and Configuration Settings……Page 204
Building Installers……Page 207
Deploying Web Applications……Page 208
Summary……Page 209
Equality, Hashing, and Comparison……Page 211
Precomputation and Partial Application……Page 214
Precomputation and Objects……Page 215
Memoizing Computations……Page 217
Lazy Values……Page 219
Cleaning Up Resources……Page 220
Cleaning Up with use……Page 221
Managing Resources with More Complex Lifetimes……Page 223
Cleaning Up Internal Objects……Page 224
Cleaning Up Unmanaged Objects……Page 226
Cleaning Up in Sequence Expressions……Page 227
Stack As a Resource: Tail Calls and Recursion……Page 228
Tail Recursion and List Processing……Page 230
Tail Recursion and Object-Oriented Programming……Page 232
Tail Recursion and Processing Unbalanced Trees……Page 233
Using Continuations to Avoid Stack Overflows……Page 234
Another Example: Processing Syntax Trees……Page 236
Events and Wiring……Page 237
Events As First-Class Values……Page 238
Creating and Publishing Events……Page 239
Summary……Page 240
Introducing Language-Oriented Programming……Page 241
Using the System.Xml Namespace……Page 242
From Concrete XML to Abstract Syntax……Page 244
Abstract Syntax Representations: fLess Is Moref……Page 247
Processing Abstract Syntax Representations……Page 248
Transformational Traversals of Abstract Syntax Representations……Page 249
Using On-Demand Computation with Abstract Syntax Trees……Page 250
Caching Properties in Abstract Syntax Trees……Page 251
Memoizing Construction of Syntax Tree Nodes……Page 252
Introducing Active Patterns……Page 254
Converting the Same Data to Many Views……Page 255
Matching on .NET Object Types……Page 257
Hiding Abstract Syntax Implementations with Active Patterns……Page 258
Embedded Computational Languages with Workflows……Page 260
An Example: Success/Failure Workflows……Page 262
Defining a Workflow Builder……Page 265
Workflows and fintamedfl ide Effects……Page 268
Example: Probabilistic Workflows……Page 269
Recursive Workflow Expressions……Page 274
Schema Compilation by Reflecting on Types……Page 275
Using F# Quotations……Page 279
Example: Using F# Quotations for Error Estimation……Page 281
Resolving Top Definitions……Page 283
Summary……Page 284
A High-Level Overview……Page 285
Namespaces from the .NET Framework……Page 286
Namespaces from the F# Libraries……Page 288
Using the System Types……Page 289
Matching with System.Text.RegularExpressions……Page 291
Formatting Strings Using .NET Formatting……Page 295
Using Further F# and .NET Data Structures……Page 296
System.Collections.Generic and Other .NET Collections……Page 297
Using Matrices and Vectors……Page 298
Using Operator Overloads on Matrices and Vectors……Page 299
Using General Types……Page 300
Using Microsoft.FSharp.Reflection……Page 301
Some Other .NET Types You May Encounter……Page 302
Some Other .NET Libraries……Page 303
Summary……Page 304
Writing fHello, World!f in a Click……Page 305
Understanding the Anatomy of a Graphical Application……Page 306
Composing User Interfaces……Page 307
Drawing Applications……Page 312
Developing a Custom Control……Page 317
Anatomy of a Control……Page 320
Displaying Samples from Sensors……Page 321
Building the GraphControl: The Model……Page 322
Building the GraphControl: Style Properties and Controller……Page 324
Building the GraphControl: The View……Page 328
Putting It Together……Page 332
Creating a Mandelbrot Viewer……Page 333
Computing Mandelbrot……Page 334
Setting Colors……Page 335
Creating the Visualization Application……Page 338
Creating the Application Plumbing……Page 340
Summary……Page 345
Working with Symbolic Representations……Page 347
Modeling Simple Algebraic Expressions……Page 348
Implementing Local Simplifications……Page 350
A Richer Language of Algebraic Expressions……Page 351
Parsing Algebraic Expressions……Page 353
Simplifying Algebraic Expressions……Page 355
Symbolic Differentiation of Algebraic Expressions……Page 358
Rendering Expressions……Page 359
Converting to VisualExpr……Page 361
Rendering……Page 364
Building the User Interface……Page 365
Verifying Circuits with Propositional Logic……Page 368
Representing Propositional Logic……Page 369
Evaluating Propositional Logic Naively……Page 370
From Circuits to Propositional Logic……Page 373
Checking Simple Properties of Circuits……Page 376
Representing Propositional Formulae Efficiently Using BDDs……Page 377
Circuit Verification with BDDs……Page 380
Summary……Page 383
Reactive, Asynchronous, and Concurrent Programming……Page 385
Introducing Some Terminology……Page 386
Using and Designing Background Workers……Page 387
Building a Simpler Iterative Worker……Page 389
Raising Additional Events from Background Workers……Page 392
Connecting a Background Worker to a GUI……Page 393
Fetching Multiple Web Pages Asynchronously……Page 395
Understanding Thread Hopping……Page 397
Under the Hood: What Are Asynchronous Computations?……Page 399
File Processing Using Asynchronous Workflows……Page 401
Running Asynchronous Computations……Page 404
Common I/O Operations in Asynchronous Workflows……Page 405
Under the Hood: Implementing a Primitive Asynchronous Step……Page 406
Under the Hood: Implementing Async.Parallel……Page 407
Understanding Exceptions and Cancellation……Page 408
Introducing Message Processing……Page 409
Creating Objects That React to Messages……Page 411
Scanning Mailboxes for Relevant Messages……Page 414
Example: Asynchronous Web Crawling……Page 415
Creating Threads Explicitly……Page 418
Shared Memory, Race Conditions, and the .NET Memory Model……Page 419
Using Locks to Avoid Race Conditions……Page 420
Using ReaderWriterLock……Page 421
Summary……Page 422
Serving Static Web Content……Page 423
Serving Dynamic Web Content with ASP.NET……Page 426
Understanding the Languages Used in ASP.NET……Page 427
A Simple ASP.NET Web Application……Page 429
Deploying and Running the Application……Page 432
Using Code-Behind Files……Page 434
Using ASP.NET Input Controls……Page 436
Displaying Data from Databases……Page 439
ASP.NET Directives……Page 442
Server Controls……Page 443
Debugging, Profiling, and Tracing……Page 445
Understanding the ASP.NET Event Model……Page 446
Maintaining the View State……Page 448
Understanding the Provider Model……Page 449
Configuring the Provider Database……Page 450
Creating Custom ASP.NET Server Controls……Page 451
Building Ajax Rich Client Applications……Page 452
More on F# Web Tools……Page 453
Using Web Services……Page 454
Consuming Web Services……Page 455
Calling Web Services Asynchronously……Page 457
Summary……Page 459
Querying In-Memory Data Structures……Page 461
Select/Where/From Queries Using Aggregate Operators……Page 462
Using Aggregate Operators in Queries……Page 463
Accumulating Using fioldingf Operators……Page 464
Expressing Some Queries Using Sequence Expressions……Page 465
Using Databases to Manage Data……Page 466
Understanding ADO.NET……Page 468
Establishing Connections to a Database Engine……Page 469
Creating a Database……Page 470
Creating Tables, Inserting, and Fetching Records……Page 472
Using Untyped Datasets……Page 474
Generating Typed Datasets Using xsd.exe……Page 476
Using Stored Procedures……Page 478
Using Data Grids……Page 479
Visual Data Modeling: Adding Relationships……Page 480
Accessing Relational Data with F# LinqToSql……Page 482
Building the DataContext Instance……Page 483
Using LinqToSql from F#……Page 484
Working with XML As a Generic Data Format……Page 485
Constructing XML via LINQ……Page 487
Storing, Loading, and Traversing LinqToXml Documents……Page 488
Summary……Page 489
Lexing and Parsing……Page 491
Processing Line-Based Input……Page 492
Using Regular Expressions……Page 493
Tokenizing with FsLex……Page 494
The fslex Input in More Detail……Page 497
Generating a Simple Token Stream……Page 498
Tracking Position Information Correctly……Page 500
Handling Comments and Strings……Page 501
Recursive-Descent Parsing……Page 503
Parsing with FsYacc……Page 507
The Lexer for Kitty……Page 508
The Parser for Kitty……Page 510
Parsing Lists……Page 512
Resolving Conflicts, Operator Precedence, and Associativity……Page 513
Putting It Together……Page 514
Binary Parsing and Pickling Using Combinators……Page 516
Summary……Page 519
Common Language Runtime……Page 521
Memory Management at Run Time……Page 524
COM Interoperability……Page 526
Platform Invoke……Page 537
Getting Started with PInvoke……Page 538
Data Structures……Page 540
Marshalling Strings……Page 543
Function Pointers……Page 546
PInvoke Memory Mapping……Page 547
Wrapper Generation and Limits of PInvoke……Page 550
Summary……Page 552
Debugging and Testing F# Programs……Page 553
Debugging F# Programs……Page 554
Using Advanced Features of the Visual Studio Debugger……Page 556
Instrumenting Your Program with the System.Diagnostics Namespace……Page 558
Debugging Concurrent and Graphical Applications……Page 561
Debugging and Testing with F# Interactive……Page 563
Controlling F# Interactive……Page 564
Understanding How F# Interactive Compiles Code……Page 565
Unit Testing……Page 567
Summary……Page 573
Designing F# Libraries……Page 575
Designing Vanilla .NET Libraries……Page 576
Understanding Where Functional Programming Comes From……Page 581
Understanding Functional Design Methodology……Page 582
Applying the .NET Design Guidelines to F#……Page 584
Some Recommended Coding Idioms……Page 590
Summary……Page 592
Comments and Attributes Basic Types and Literals……Page 593
Unknown……Page 0
Types Patterns and Matching Functions, Composition, and Pipelining……Page 594
Binding and Control Flow Exceptions……Page 595
Tuples, Arrays, Lists, and Collections……Page 596
Operators……Page 597
Type Definitions and Objects……Page 598
Namespaces and Modules Sequence Expressions and Workflows……Page 599
Index……Page 601

Reviews

There are no reviews yet.

Be the first to review “Expert F#”
Shopping Cart
Scroll to Top